diff --git a/Assets/Tests/InputSystem/CoreTests_Events.cs b/Assets/Tests/InputSystem/CoreTests_Events.cs index bf504f2274..c3dc4c7cfd 100644 --- a/Assets/Tests/InputSystem/CoreTests_Events.cs +++ b/Assets/Tests/InputSystem/CoreTests_Events.cs @@ -179,6 +179,45 @@ public void Events_CanListenForButtonPresses() InputSystem.Update(); } + [Test] + [Category("Events")] + public void Events_OnAnyButtonPressed_FiltersOutOtherControls() + { + InputSystem.settings.defaultButtonPressPoint = 0.5f; + + var mouse = InputSystem.AddDevice(); + + var callCount = 0; + + InputSystem.onAnyButtonPress + .Call(ctrl => + { + Assert.That(ctrl, Is.SameAs(mouse.leftButton)); + ++callCount; + }); + + Assert.That(callCount, Is.Zero); + + InputSystem.Update(); + + InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left)); + InputSystem.Update(); + + Assert.That(callCount, Is.EqualTo(1)); + + var mouseState = new MouseState(); + mouseState.position.x = 3f; + InputSystem.QueueStateEvent(mouse, mouseState.WithButton(MouseButton.Left)); + InputSystem.Update(); + + Assert.That(callCount, Is.EqualTo(1)); + + InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left, false)); + InputSystem.Update(); + + Assert.That(callCount, Is.EqualTo(1)); + } + [Test] [Category("Events")] public void Events_OnAnyButtonPressed_FiltersOutNonStateEvents() diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index a691fdd3c9..aa5e19e05e 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -30,6 +30,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed the compilation warnings when used with Unity 6.4 (ISX-2349). - 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) - 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). +- 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). - 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) - Fixed formatting issues on processor documentation page diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs index e43dc6cec8..3e308d86e1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs @@ -1114,6 +1114,8 @@ public static InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude)) { + if (!control.HasValueChangeInEvent(eventPtr)) + continue; if (buttonControlsOnly && !control.isButton) continue; return control;