Skip to content

Commit 6e964ce

Browse files
ritamerklK-Tone
andauthored
FIX: Sort out controls which are not contained in event for AnyButtonPressed event (ISXB-1005) (#2249)
Co-authored-by: Anthony Yakovlev <[email protected]>
1 parent 54553a7 commit 6e964ce

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Assets/Tests/InputSystem/CoreTests_Events.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,45 @@ public void Events_CanListenForButtonPresses()
179179
InputSystem.Update();
180180
}
181181

182+
[Test]
183+
[Category("Events")]
184+
public void Events_OnAnyButtonPressed_FiltersOutOtherControls()
185+
{
186+
InputSystem.settings.defaultButtonPressPoint = 0.5f;
187+
188+
var mouse = InputSystem.AddDevice<Mouse>();
189+
190+
var callCount = 0;
191+
192+
InputSystem.onAnyButtonPress
193+
.Call(ctrl =>
194+
{
195+
Assert.That(ctrl, Is.SameAs(mouse.leftButton));
196+
++callCount;
197+
});
198+
199+
Assert.That(callCount, Is.Zero);
200+
201+
InputSystem.Update();
202+
203+
InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left));
204+
InputSystem.Update();
205+
206+
Assert.That(callCount, Is.EqualTo(1));
207+
208+
var mouseState = new MouseState();
209+
mouseState.position.x = 3f;
210+
InputSystem.QueueStateEvent(mouse, mouseState.WithButton(MouseButton.Left));
211+
InputSystem.Update();
212+
213+
Assert.That(callCount, Is.EqualTo(1));
214+
215+
InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left, false));
216+
InputSystem.Update();
217+
218+
Assert.That(callCount, Is.EqualTo(1));
219+
}
220+
182221
[Test]
183222
[Category("Events")]
184223
public void Events_OnAnyButtonPressed_FiltersOutNonStateEvents()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ however, it has to be formatted properly to pass verification tests.
3030
- Fixed the compilation warnings when used with Unity 6.4 (ISX-2349).
3131
- Fixed an issue where `InputSystemUIInputModule.localMultiPlayerRoot` could not be set to `null` when using `MultiplayerEventSystem`. [ISXB-1610](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1610)
3232
- Fixed an issue in `Keyboard` where the sub-script operator would return a `null` key control for the deprecated key `Key.IMESelected`. Now, an aliased `KeyControl`mapping to the IMESelected bit is returned for compability reasons. It is still strongly advised to not rely on this key since `IMESelected` bit isn't strictly a key and will be removed from the `Key` enumeration type in a future major revision. [ISXB-1541](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1541).
33+
- Fixed an issue where the onAnyButtonPress callback would be triggered multiple times during unrelated events when a button is held down. See [ISXB-1005](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1005).
3334
- Fixed InputControl picker not updating correctly when the Input Actions Window was dirty. [ISXB-1221](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1221)
3435
- Fixed formatting issues on processor documentation page
3536

Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ public static InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr
11141114

11151115
foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude))
11161116
{
1117+
if (!control.HasValueChangeInEvent(eventPtr))
1118+
continue;
11171119
if (buttonControlsOnly && !control.isButton)
11181120
continue;
11191121
return control;

0 commit comments

Comments
 (0)