Input: report the character each held key types #656

Open
lameloball2813-ui wants to merge 1 commit from upstream-pr/656 into main
lameloball2813-ui commented 2026-11-24 06:21:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lameloball2813-ui on 2026-11-24T06:21:31Z.


Held keys reported code point 0 (the shortcut: in gameinput.rs's host source). They now report the character they type, as GameInput's keyboard state does:

  • ToUnicodeEx with the foreground window's keyboard layout, so it follows the user's layout.
  • The keyboard state it reads is built from the keys held this poll. Devices report left/right modifiers only, so either side's Shift/Ctrl/Alt also sets the generic one. Caps Lock's toggle comes from GetKeyState.
  • Called with flag 4 (keep keyboard state), so polling never eats a pending dead key the title's window is composing.
  • Dead keys set dead_key, with the accent's spacing form as the code point. Keys that type nothing, or several characters at once, report 0.

Grand Theft Auto VI reads scan codes and virtual keys only, so nothing changes for it. This fills in the platform side for titles that read characters.

Testing

Windows 11, RTX 5060 Ti. Not tested in a title (I don't have one to run).

  • Two new tests in gameinput::host: modifier sides set the generic modifier and Caps Lock sets its toggle; Space and Enter type 0x20/0x0D and F1 types nothing in the machine's layout (layout-independent keys only).
  • cargo test --workspace: everything passes except victory-loader's load_probe, which fails before and after this change on my machine. It builds the fixture into target/fixtures inside the checkout, and my checkout's path is long enough that link.exe hits LNK1104 (MAX_PATH). Unrelated to this change.
  • cargo clippy -p victory-hle --all-targets: no warnings in gameinput.rs. cargo xtask policy: ok.

Not covered: dead keys and Caps Lock have no automated test (they depend on the machine's layout and toggle state), and I haven't checked them by hand on a layout with dead keys.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575957265 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656). Originally posted by [lameloball2813-ui](https://github.com/lameloball2813-ui) on 2026-11-24T06:21:31Z. --- Held keys reported code point 0 (the `shortcut:` in `gameinput.rs`'s host source). They now report the character they type, as GameInput's keyboard state does: - `ToUnicodeEx` with the foreground window's keyboard layout, so it follows the user's layout. - The keyboard state it reads is built from the keys held this poll. Devices report left/right modifiers only, so either side's Shift/Ctrl/Alt also sets the generic one. Caps Lock's toggle comes from `GetKeyState`. - Called with flag 4 (keep keyboard state), so polling never eats a pending dead key the title's window is composing. - Dead keys set `dead_key`, with the accent's spacing form as the code point. Keys that type nothing, or several characters at once, report 0. Grand Theft Auto VI reads scan codes and virtual keys only, so nothing changes for it. This fills in the platform side for titles that read characters. ## Testing Windows 11, RTX 5060 Ti. Not tested in a title (I don't have one to run). - Two new tests in `gameinput::host`: modifier sides set the generic modifier and Caps Lock sets its toggle; Space and Enter type `0x20`/`0x0D` and F1 types nothing in the machine's layout (layout-independent keys only). - `cargo test --workspace`: everything passes except `victory-loader`'s `load_probe`, which fails before and after this change on my machine. It builds the fixture into `target/fixtures` inside the checkout, and my checkout's path is long enough that `link.exe` hits LNK1104 (MAX_PATH). Unrelated to this change. - `cargo clippy -p victory-hle --all-targets`: no warnings in `gameinput.rs`. `cargo xtask policy`: ok. Not covered: dead keys and Caps Lock have no automated test (they depend on the machine's layout and toggle state), and I haven't checked them by hand on a layout with dead keys.
LAKSHYA-cmd-tech commented 2026-11-24 06:54:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:25:07Z.

Review: APPROVED


LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 88 unit tests in ictory-hle pass cleanly, including the new keyboard_held_keys_return_typed_characters test. Keystroke typing mapping properly differentiates control keys and character typing.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034637351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656#pullrequestreview-6034637351). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T06:25:07Z. **Review:** APPROVED --- LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 88 unit tests in ictory-hle pass cleanly, including the new keyboard_held_keys_return_typed_characters test. Keystroke typing mapping properly differentiates control keys and character typing.
mercuryVM commented 2026-11-24 11:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:51:34Z.

Review: APPROVED


Tested 3b001ed on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 89 passed, including either_sides_modifier_holds_the_generic_one. Clippy's 1 warning is the existing one at xmem.rs:747. I didn't drive real key input here, so ToUnicodeEx output is checked by reading the code, not by a run.

  • Building the state array from this poll's held keys, rather than reading GetKeyboardState, keeps the result independent of which thread polls. Flag 4 keeps the thread's dead-key state intact, so a title's own text input isn't disturbed.
  • AltGr arrives as LCtrl+RAlt and maps to generic Ctrl+Alt here, which ToUnicodeEx treats as AltGr on layouts that have it. Good.
  • Behaviour to be aware of: with Ctrl held, ToUnicodeEx returns control characters (Ctrl+A gives U+0001), so those now come back as code_point 1–26 instead of 0. If GameInput reports 0 or the plain letter in that case, it would be worth filtering c < ' ' back to 0. I don't have a reference capture to say which is right.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037883587 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656#pullrequestreview-6037883587). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:51:34Z. **Review:** APPROVED --- Tested 3b001ed on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 89 passed, including `either_sides_modifier_holds_the_generic_one`. Clippy's 1 warning is the existing one at xmem.rs:747. I didn't drive real key input here, so `ToUnicodeEx` output is checked by reading the code, not by a run. - Building the state array from this poll's held keys, rather than reading `GetKeyboardState`, keeps the result independent of which thread polls. Flag 4 keeps the thread's dead-key state intact, so a title's own text input isn't disturbed. - AltGr arrives as LCtrl+RAlt and maps to generic Ctrl+Alt here, which `ToUnicodeEx` treats as AltGr on layouts that have it. Good. - Behaviour to be aware of: with Ctrl held, `ToUnicodeEx` returns control characters (Ctrl+A gives U+0001), so those now come back as `code_point` 1–26 instead of 0. If GameInput reports 0 or the plain letter in that case, it would be worth filtering `c < ' '` back to 0. I don't have a reference capture to say which is right. AI-assisted (Claude Code).
geiyiliyabumo commented 2026-11-24 12:04:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T11:39:34Z.


Independent verification & code review on Windows 11 Pro (build 26100, Rust 1.98.1), cleanly merged onto main (ffe310e):

  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: PASS
  • cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings: PASS
  • cargo test -p victory-hle --locked: 96 passed + 1 integration test (no_dll_planting), 0 failed (including new either_sides_modifier_holds_the_generic_one and keys_type_their_characters)

Diff review (crates/victory-hle/src/modules/gameinput.rs): clean and thoughtful — using ToUnicodeEx with flag 4 (KEEP_STATE) avoids mutating keyboard dead-key state, and populating generic 0x10..=0x12 from sided 0xA0..=0xA5 ensures Shift/Ctrl/Alt modifiers work accurately.

  • Tiny non-blocking note: when ToUnicodeEx returns n < 0 (dead key), &text[..1] covers BMP dead keys; using n.unsigned_abs() as usize (clamped to text.len()) would also preserve a 2-unit surrogate pair if a layout ever emits a non-BMP dead-key spacing character.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7130381088 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656#issuecomment-7130381088). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T11:39:34Z. --- Independent verification & code review on Windows 11 Pro (build 26100, Rust `1.98.1`), cleanly merged onto `main` (`ffe310e`): - `cargo xtask policy`: PASS (`154 files ok`) - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: PASS - `cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings`: PASS - `cargo test -p victory-hle --locked`: **96 passed + 1 integration test (`no_dll_planting`), 0 failed** (including new `either_sides_modifier_holds_the_generic_one` and `keys_type_their_characters`) Diff review (`crates/victory-hle/src/modules/gameinput.rs`): clean and thoughtful — using `ToUnicodeEx` with flag `4` (`KEEP_STATE`) avoids mutating keyboard dead-key state, and populating generic `0x10..=0x12` from sided `0xA0..=0xA5` ensures Shift/Ctrl/Alt modifiers work accurately. - Tiny non-blocking note: when `ToUnicodeEx` returns `n < 0` (dead key), `&text[..1]` covers BMP dead keys; using `n.unsigned_abs() as usize` (clamped to `text.len()`) would also preserve a 2-unit surrogate pair if a layout ever emits a non-BMP dead-key spacing character. *AI-assisted; synthetic tests only, no game files.*
molodayamama commented 2026-11-24 14:05:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:04:26Z.


Independent Windows check of 3b001ed80c97a9da158696ae06c4961548953a53 (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).

  • cargo test -p victory-hle --locked --lib either_sides_modifier_holds_the_generic_one -- --test-threads=1 --nocapture: 1 passed.
  • cargo test -p victory-hle --locked --lib keys_type_their_characters -- --test-threads=1 --nocapture: 1 passed.

The focused checks passed for left/right modifier aliases and the characters produced from held keys.

Only source-built synthetic fixtures were used. AI-assisted verification.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133796651 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656#issuecomment-7133796651). Originally posted by [molodayamama](https://github.com/molodayamama) on 2026-11-24T14:04:26Z. --- Independent Windows check of `3b001ed80c97a9da158696ae06c4961548953a53` (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64). - `cargo test -p victory-hle --locked --lib either_sides_modifier_holds_the_generic_one -- --test-threads=1 --nocapture`: 1 passed. - `cargo test -p victory-hle --locked --lib keys_type_their_characters -- --test-threads=1 --nocapture`: 1 passed. The focused checks passed for left/right modifier aliases and the characters produced from held keys. Only source-built synthetic fixtures were used. AI-assisted verification.
Marvisak commented 2026-11-25 02:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:16:51Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-hle/src/modules/gameinput.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149386859 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/656#issuecomment-7149386859). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:16:51Z. --- <!-- victory-triage v1 head=3b001ed80c97a9da158696ae06c4961548953a53 verdict=needs-rebase at=2026-11-25T01:16:51Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-hle/src/modules/gameinput.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/656:upstream-pr/656'
git switch 'upstream-pr/656'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/656'
git switch 'upstream-pr/656'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/656'
git switch 'upstream-pr/656'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/656'
git switch 'main'
git merge --squash 'upstream-pr/656'
git switch 'main'
git merge --ff-only 'upstream-pr/656'
git switch 'main'
git merge 'upstream-pr/656'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!656
No description provided.