Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ public void Events_CanListenForButtonPresses()
InputSystem.Update();
}

[Test]
[Category("Events")]
public void Events_OnAnyButtonPressed_FiltersOutOtherControls()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have a test. I assume this test would fail before your change, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

{
InputSystem.settings.defaultButtonPressPoint = 0.5f;

var mouse = InputSystem.AddDevice<Mouse>();

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()
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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).

## [1.14.2] - 2025-08-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down