Skip to content

FIX: [Port] [UUM-144317] [Input System] Fixed Keyboard.anyKey.wasPressedThisFrame while another key is held - #2504

Open
K-Tone wants to merge 1 commit into
developfrom
uum-144317-anykey-was-pressed
Open

K-Tone wants to merge 1 commit into
developfrom
uum-144317-anykey-was-pressed

Conversation

@K-Tone

@K-Tone K-Tone commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Port of the trunk fix for UUM-144317 (unity/unity PR #135085).

Keyboard.current.anyKey.wasPressedThisFrame was not true when a key went down while another key (e.g. Shift) was already held. anyKey is an AnyKeyControl, a button that is pressed for as long as any key is held, so holding Shift and then pressing A never transitioned it from released to pressed (there was a ////TODO: wasPressedThisFrame and wasReleasedThisFrame in the class for this).

Changes:

  • ButtonControl press tracking (UpdateWasPressed/UpdateWasPressedEditor and BeginTestingForFramePresses) calls a new internal virtual CheckForRepress, which returns false by default, so other buttons are unchanged and there is no public API change.
  • AnyKeyControl overrides it: it keeps a copy of its key bits from the last press-state update (separately for editor and player state) and reports a new press when a key that wasn't down goes down. When press tracking starts, it compares against the previous frame, so the first wasPressedThisFrame query also catches such a press.
  • New internal InputControl.GetStatePtr(InputUpdateType, bool) reads the state buffers of a given update type. AnyKeyControl uses it so the editor and player snapshots never get mixed up when press tracking is refreshed while the other state is current (e.g. after a settings change).

wasReleasedThisFrame still only fires when the last key is released, so anyKey can now report several presses in a row without a release in between. This is documented on AnyKeyControl and in the changelog.

The code merged cleanly onto develop and matches trunk; the only difference is fixed( spacing from ./format.sh.

Testing status & QA

New tests in CoreTests_Devices:

  • Devices_AnyKeyOnKeyboard_WasPressedThisFrame_WhenKeyGoesDownWhileAnotherIsHeld (delta events through Press/Release)
  • ..._WithFullStateEvents (full KeyboardState events, as sent by the platform backends)
  • ..._WhenFirstQueriedAsKeyGoesDownWhileAnotherIsHeld (first query in the frame the key goes down)
  • ..._KeepsEditorAndPlayerStateApart_WhenSettingsChange (editor only)

Not run locally against this branch; relying on CI.

QA: in Play Mode, poll Keyboard.current.anyKey.wasPressedThisFrame every frame, hold Shift, then press A — it should be true in the frame A goes down. Releasing A while Shift is still held should report neither a press nor a release.

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Medium — ButtonControl press tracking is shared by all buttons, though only AnyKeyControl changes behavior.

Comments to reviewers

The trunk PR #135085 is approved but not merged yet; this port will be updated if it changes before merging.

Checklist

Before review:

  • Changelog entry added.
  • Tests added/changed, if applicable.
  • Docs for new/changed API's. (n/a — no public API changes; AnyKeyControl remarks updated)

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

🤖 Generated with Claude Code

…sedThisFrame while another key is held

Port of unity/unity trunk PR #135085.

anyKey is pressed for as long as any key is held, so a key going down while
another one was held never registered as a press. AnyKeyControl now keeps a
copy of its key bits (separately for editor and player state) and reports a
new press when a key goes down, via a new internal virtual
ButtonControl.CheckForRepress. wasReleasedThisFrame still only fires when the
last key is released. Adds InputControl.GetStatePtr(InputUpdateType, bool) to
read the state of a specific update type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@K-Tone
K-Tone requested a review from ritamerkl November 9, 2026 10:49

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Harness Review

Needs changes

The overlapping-key fix has focused regression coverage, but the shared-control change needs a compatibility correction.

Reviewed commit 6e5aeb6

🤖 Helpful? 👍/👎

var endBit = m_StateBlock.bitOffset + m_StateBlock.sizeInBits;
for (var bit = m_StateBlock.bitOffset; bit < endBit; ++bit)
{
if (MemoryHelpers.ReadSingleBit(statePtr, bit) && !MemoryHelpers.ReadSingleBit(lastStatePtr, bit))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1

Once trigger is being tracked, a WebGL joystick falsely reports wasPressedThisFrame when a held button decreases from 1.0f to 0.75f. WebGLLayoutBuilder.Build uses AnyKeyControl for Trigger, spanning 32-bit float button fields. Changing 1.0f to 0.75f sets a mantissa bit while the aggregate control remains pressed. CheckForRepress interprets that raw bit change as another button press. Restrict bitwise repress detection to actual key-bit state. Preserve aggregate-transition behavior for float-backed AnyKeyControl instances. Add coverage for decreasing a held WebGL button's float value.

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.80000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...stem/InputSystem/Runtime/Controls/ButtonControl.cs 69.56% 7 Missing ⚠️
...stem/InputSystem/Runtime/Controls/AnyKeyControl.cs 97.14% 1 Missing ⚠️
...ystem/InputSystem/Runtime/Controls/InputControl.cs 85.71% 1 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2504      +/-   ##
===========================================
+ Coverage    78.96%   79.21%   +0.24%     
===========================================
  Files          767      769       +2     
  Lines       140949   141372     +423     
===========================================
+ Hits        111305   111984     +679     
+ Misses       29644    29388     -256     
Flag Coverage Δ
inputsystem_MacOS_6000.0 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.0_project 77.90% <92.80%> (+0.38%) ⬆️
inputsystem_MacOS_6000.3 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.3_project 77.89% <92.80%> (+0.39%) ⬆️
inputsystem_MacOS_6000.6 5.29% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.6_project 77.95% <92.80%> (+0.38%) ⬆️
inputsystem_Ubuntu_6000.0 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.0_project 77.81% <92.80%> (+0.38%) ⬆️
inputsystem_Ubuntu_6000.3 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.3_project 77.80% <92.80%> (+0.38%) ⬆️
inputsystem_Ubuntu_6000.6 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.6_project 77.86% <92.80%> (+0.38%) ⬆️
inputsystem_Windows_6000.0 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.0_project 78.02% <92.80%> (+0.38%) ⬆️
inputsystem_Windows_6000.3 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.3_project 78.01% <92.80%> (+0.38%) ⬆️
inputsystem_Windows_6000.6 5.29% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.6_project 78.07% <92.80%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Devices.cs 98.26% <100.00%> (+0.03%) ⬆️
...stem/InputSystem/Runtime/Controls/AnyKeyControl.cs 97.67% <97.14%> (-2.33%) ⬇️
...ystem/InputSystem/Runtime/Controls/InputControl.cs 81.05% <85.71%> (+0.07%) ⬆️
...stem/InputSystem/Runtime/Controls/ButtonControl.cs 80.73% <69.56%> (-1.49%) ⬇️

... and 10 files with indirect coverage changes

ℹ️ Need help interpreting these results?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant