Skip to content

GameInput: held keys are reported in the order they were pressed, as documented - #927

Open
BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:hle/held-keys-in-press-order
Open

BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:hle/held-keys-in-press-order

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

Microsoft's GameInput keyboard and mouse documentation specifies the order of the array returned by IGameInputReading::GetKeyState:

"New keys are added at the end of the array, and when a key is released, everything shifts down to fill in the gap."

In crates/victory-hle/src/modules/gameinput.rs:1158-1163, host::Host::keys rebuilds the held-key list on every poll by scanning virtual-key codes in ascending numerical order:

let held: Vec<u8> = (0x08..=0xFE_u8)
    .filter(|vk| !(0x10..=0x12).contains(vk) && !down.contains(vk))
    // SAFETY: plain queries.
    .filter(|&vk| unsafe { GetAsyncKeyState(i32::from(vk)) } < 0)
    .collect();
down.extend(held);

key_state (crates/victory-hle/src/modules/gameinput.rs:1003-1014) copies that list directly into the caller's GameInputKeyState buffer. If the player holds Z (0x5A) and then also presses A (0x41), GameInput documents [Z, A], while VIctory reports [A, Z].

Impact

Key-binding screens and any title code that identifies the most recently pressed key from the end of the GetKeyState array read the wrong key whenever a newly pressed key has a lower virtual-key code than a key already held (for example, binding Z when the player pressed A).

What the fix does

Track the previous poll's held virtual keys on host::Host and compute the next ordered list with a small pure press_order(previous, down) helper: keep keys from previous that are still in down in their existing order, then append keys in down that were not in previous. Because PR #656 also edits Host::keys, the helper lives outside keys and the change inside keys is limited to applying press_order and iterating self.held_keys, leaving key scanning, filtering, and KeyState construction untouched.

Tests

held_keys_keep_their_press_order exercises press_order with these sequences:

  • Z held, then A pressed: [Z, A]. Today's scan gives [A, Z].
  • B added: [Z, A, B].
  • Z released: [A].
  • Z pressed again: it goes to the end, [A, Z].

On GitHub's windows-latest, with the upstream CI's commands (clippy -D warnings with and without --all-features, then cargo test --workspace --locked), everything passes: victory-hle 95 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45399104790).

Not tested: a title's key-binding screen.

No game data used. AI-assisted: found with GPT-6.2 Astra, written with Gemini 4 Neon, reviewed and verified with Claude Code.

Fixes #874.

🤖 Generated with Claude Code

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested head 4ce99c1 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-hle: 95 passed, 0 failed (plus no_dll_planting: 1 passed), including modules::gameinput::tests::held_keys_keep_their_press_order
  • cargo clippy -p victory-hle --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean fix preserving press order for held keys. Approving.

AI-assisted (Gemini 4 Neon).

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4ce99c1: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. keys() now builds its KeyStates through key_state, so the change is just press_order applied before that map. gameinput tests: 10 passed under Wine, held_keys_keep_their_press_order and scripted_keys_merge_into_connected_host_pad included.

@BastienRodz
BastienRodz force-pushed the hle/held-keys-in-press-order branch from 4ce99c1 to d8f9221 Compare November 25, 2026 00:27
@BastienRodz

Copy link
Copy Markdown
Contributor Author

The CI failure is only victory-shader's gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out. main fails those two the same way on the runner's software adapter, and #1752 fixes them. victory-hle, the only crate this PR touches, passes, gameinput tests included.

@BastienRodz
BastienRodz force-pushed the hle/held-keys-in-press-order branch from d8f9221 to bf0f22a Compare November 25, 2026 00:46
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Still red on the same two victory-shader tests: main's own CI after 42363ab fails them too. The runner's Basic Render Driver doesn't set the software flag that commit checks. #1919 adds its vendor/device ids, and windows-latest is green with it. This PR's crate passes.

@BastienRodz
BastienRodz force-pushed the hle/held-keys-in-press-order branch from bf0f22a to cd16903 Compare November 25, 2026 01:14

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate. Re-reviewed at 0832e0a, which merges cleanly into main. ISSUE_DRAFT.md is gone, and the PR touches only crates/victory-hle/src/modules/gameinput.rs, as you said. press_order keeps the previous poll's held keys in order and appends new ones once. host::Host::keys now reports held_keys in that order, which matches the documented GetKeyState ordering. held_keys_keep_their_press_order covers a lower virtual-key code pressed second, releasing a middle key and the first key, pressing a key again, and a duplicate in one reading.

CI: passing. Recommending a look, not approving.


Generated by Claude Code

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
VlREX added a commit to VlREX/VIREX that referenced this pull request Nov 25, 2026
Cover small output buffers, retained readings, and stable sequence numbers.
The buffer and snapshot cases are adapted from MichaelSmithAI's
BastienRodz#2 regression based on Marvisak#927.
Place the test next to the keyboard reading tests so it can merge with Marvisak#2715.
zebraso added a commit to zebraso/VIctory that referenced this pull request Nov 25, 2026
zebraso added a commit to zebraso/VIctory that referenced this pull request Nov 25, 2026
…) - halves_only active, half_views plumbing
zebraso added a commit to zebraso/VIctory that referenced this pull request Nov 25, 2026
…) - halves_only active, half_views plumbing
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
…documented

Microsoft's GameInput documentation for IGameInputReading::GetKeyState
states: "New keys are added at the end of the array, and when a key is
released, everything shifts down to fill in the gap." Previously,
host::Host::keys rebuilt the held-key list on every poll in ascending
virtual-key order, so holding Z and then pressing A reported [A, Z]
instead of [Z, A].

Remember the previous poll's held virtual keys on host::Host and order
each poll's result with a pure press_order helper that keeps still-held
keys in their prior order and appends newly pressed keys at the end.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz
BastienRodz force-pushed the hle/held-keys-in-press-order branch from cd16903 to 10dd254 Compare November 25, 2026 21:55
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and Windows 11 verification at head 10dd2549d4da merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-hle/src/modules/gameinput.rs:1145-1152, 1217, 1261-1262):
    • press_order retains held keys in prior press order and appends newly pressed keys, clears cleanly on focus loss (press_order(&self.held_keys, &[])), and integrates cleanly with State::update ordered equality and key_state truncation.
    • Two minor non-blocking notes: (1) under diagnostics, duplicate VKs emitted in the same VICTORY_KEYS window aren't deduped before appending; (2) in held_keys_keep_their_press_order (line 1916), passing &held (b"ZA") instead of &with_b (b"ZAB") only tests releasing the first key rather than releasing a middle key.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-hle --tests -- -D warnings: 0 warnings
    • victory-hle -- gameinput: 11/11 passed.

LGTM.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks, both notes taken in 6166c20:

  1. press_order now appends each key once, so a key listed twice in one reading (scripted VICTORY_KEYS in diagnostics builds) is held once.
  2. The test now releases a middle key (ZAB with BZ down gives ZB) and the first key (ZAB with AB down gives AB), re-presses Z at the end, and checks AA gives A.

gameinput tests (11) pass under Wine, and cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

From review: `press_order` appended a key as often as a reading listed
it (scripted VICTORY_KEYS in diagnostics builds can). It now appends each
key once. The test also releases a key in the middle of the held ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz
BastienRodz force-pushed the hle/held-keys-in-press-order branch from 6166c20 to 0832e0a Compare November 26, 2026 02:19
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Removed: ISSUE_DRAFT.md was a stray untracked file in my checkout, and my commit picked it up by mistake. 0832e0a is the same change without it; the PR touches crates/victory-hle/src/modules/gameinput.rs only.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…r bits

The network that animates faces moves its tensors with
buffer_load_format_d16_* and buffer_store_format_d16_* through
R16G16B16A16_UINT and R16_UINT views, half floats and 16-bit indices
side by side. On the console each channel's 16 bits go as they are. The
translation loaded and stored them as floats (bufferLoad.f32, then
legacyF32ToF16; legacyF16ToF32, then bufferStore.f32) through those
integer views: D3D12 leaves that undefined. On this machine's RTX 4070 Ti
one of the 65,536 patterns survives the float round trip (the new device
test prints it); the PR measured the network's arena all zeros on an RTX
5080.

Now a d16 typed buffer access through a descriptor loaded from a fixed
place in a table moves unsigned integers (bufferLoad.i32 and
bufferStore.i32, the handle annotated u32), and so does a whole-dword
format load whose every channel is read only as a half float (emit/
halves.rs: the head program reads the network's output that way), where
every access through that place moves halves and the program picks
nothing from that table at run time. HostShader::half_views names those
places (the shader cache keeps them); State::tables makes a table with a
16-bit float or signed buffer view at such a place afresh, with that
view in the unsigned format of its layout (descriptor::host::half_view),
and the title's own slot keeps its format. A view whose values the
console would convert (wider, normalised, signed 8-bit) is logged once;
the first half place a draw binds is logged once too.

Everything else keeps the float path: root views, heap-picked
descriptors, places also read as whole floats.

From fxceless/victory-fork PR Marvisak#927 (with its review fixes and tests),
fitted to this tree: the d16 shortcut comments of lower.rs are now the
fallback's, and normalised format loads (b2ec3df) and view formats are
untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callimann8 pushed a commit to Callimann8/VIctory-fork that referenced this pull request Nov 26, 2026
…y are (pull request Marvisak#927), SDWA sign extension of 16-bit results (upstream VIctory Marvisak#3124); two switches off by default (clamp windows, occlusion queries) and offline tools

- Marvisak#927 (tippythetaidum): a buffer_load_format whose every use takes a half as
  f16, and d16 typed loads and stores at a table's fixed places, move 16-bit
  integers bit-exactly through unsigned twin views (HostShader::half_views).
  The face network reads its indices this way: mouths open and move (confirmed
  in a test run on an RTX 4070). Thank you, tippythetaidum.
- upstream Marvisak#3124: SDWA dst_unused 1 (sext) with WORD_0 copies bit 15 upward;
  the reserved dst_unused 3 is refused.
- VICTORY_CLAMP_WINDOW=1|alt (after upstream Marvisak#3197): indirect draws clamped a
  window at a time. Measured on this layer: 1.0 draw a pass (nothing joins):
  stays off.
- VICTORY_OCCLUSION=1|alt (after upstream Marvisak#3138): the title's occlusion
  queries answered by the card; a counter of queries by kind (the title begins
  thousands). Not yet measured: off.
- translate: VICTORY_NATIVE_HEADS lists each container program's first bytes;
  an ignored test decodes a raw GFX10 code file; the native pipeline dump
  writes root signatures. (Device methods 0x1c8 / 0x218 turned out to be a
  precompiled-pipeline cache the title falls back from.)

The shader translator changed: delete both shader caches before the first run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GameInput: held keys come back in virtual-key order, not in the order they were pressed

5 participants