Report keyboard glyphs and dead keys using the focused window layout #2755

Open
maxence468 wants to merge 1 commit from upstream-pr/2757 into main
maxence468 commented 2026-11-25 19:48:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by maxence468 on 2026-11-25T19:48:56Z.


Keyboard readings always returned zero for codePoint and false for isDeadKey. Resolve these fields from the keyboard layout of the focused title window using MapVirtualKeyExW. Scripted inputs without a focused title window use the polling thread layout. This supplies key labels to GameInput clients without consuming dead-key state. Tested on a French AZERTY Windows system, including é, dead circumflex and right Ctrl. All ten GameInput tests passed with default features and with diagnostics enabled. No in-game UI was tested.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6612432248 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757). Originally posted by [maxence468](https://github.com/maxence468) on 2026-11-25T19:48:56Z. --- Keyboard readings always returned zero for codePoint and false for isDeadKey. Resolve these fields from the keyboard layout of the focused title window using MapVirtualKeyExW. Scripted inputs without a focused title window use the polling thread layout. This supplies key labels to GameInput clients without consuming dead-key state. Tested on a French AZERTY Windows system, including é, dead circumflex and right Ctrl. All ten GameInput tests passed with default features and with diagnostics enabled. No in-game UI was tested.
kotekompotek commented 2026-11-25 21:03:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:07:45Z.


Correct use of MAPVK_VK_TO_CHAR: low word is the keycap glyph, high bit flags a dead key, and the query doesn't consume a pending accent. Querying the foreground thread's layout (not the calling thread's) is the right detail - it matches the layout actually active in our window. The GetKeyboardLayout(0) fallback for scripted keys keeps diagnostics working unfocused.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173229211 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173229211). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:07:45Z. --- Correct use of MAPVK_VK_TO_CHAR: low word is the keycap glyph, high bit flags a dead key, and the query doesn't consume a pending accent. Querying the foreground thread's layout (not the calling thread's) is the right detail - it matches the layout actually active in our window. The GetKeyboardLayout(0) fallback for scripted keys keeps diagnostics working unfocused.
cloph-dsp commented 2026-11-25 21:03:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T20:13:44Z.


Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • \cargo test --locked -p victory-hle --lib gameinput --quiet\ -> 10 passed, 0 failed (137 filtered).
  • Same with --features diagnostics\ -> 10 passed, 0 failed.
  • \git diff --check origin/main..HEAD\ clean; origin/main is an ancestor of the PR head.
  • Negative control: \keyboard_readings_include_keycap_and_extended_scan_code\ is absent from origin/main, so the test is new here.
  • The change queries MapVirtualKeyExW with MAPVK_VK_TO_VSC_EX and MAPVK_VK_TO_CHAR for the focused layout, derives code_point (low 16 bits) and dead_key (0x8000_0000), guarded by a layout availability check; the AZERTY assertions are layout-gated.
  • Only pre-existing deprecation warnings in victory-gpu/object.rs and victory-hle/xmem.rs.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173364593 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173364593). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T20:13:44Z. --- Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup. - \cargo test --locked -p victory-hle --lib gameinput --quiet\ -> 10 passed, 0 failed (137 filtered). - Same with \--features diagnostics\ -> 10 passed, 0 failed. - \git diff --check origin/main..HEAD\ clean; origin/main is an ancestor of the PR head. - Negative control: \keyboard_readings_include_keycap_and_extended_scan_code\ is absent from origin/main, so the test is new here. - The change queries MapVirtualKeyExW with MAPVK_VK_TO_VSC_EX and MAPVK_VK_TO_CHAR for the focused layout, derives code_point (low 16 bits) and dead_key (0x8000_0000), guarded by a layout availability check; the AZERTY assertions are layout-gated. - Only pre-existing deprecation warnings in victory-gpu/object.rs and victory-hle/xmem.rs. AI-assisted (Hy4 flash).
oni-swr commented 2026-11-25 21:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:15:40Z.


Independent WARP/CPU verification for head 9ff50e868e against origin/main 13f91caee2. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment.

Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). VICTORY_WARP=1 and VICTORY_D3D12_WARP=1 set (WARP only, no physical GPU); no game files. CARGO_TARGET_DIR=D:\victory-warp-2741-target. Tested commit: the PR head itself, which is exactly one commit on top of origin/main (merge-base = origin/main, so no temporary merge was needed). Host keyboard layouts: de-CH, en-GB (a Windows API test, so it ran on the real host layout; no layout was switched).

Commands/results:

  • Baseline (origin/main): cargo test --locked -p victory-hle — lib 146 passed, 0 failed; other binaries pass. cargo clippy --locked -p victory-hle --all-targets -- -D warnings — pass.
  • PR: cargo test --locked -p victory-hle --lib keyboard_readings — 1/1 passed. cargo test --locked -p victory-hle — lib 147 passed (+1), 0 failed; and with --features diagnostics also lib 147 passed, 0 failed. Clippy --all-targets -- -D warnings passes with and without --features diagnostics.
  • Negative controls (restored, tree clean): code_point: 0 (the pre-PR value) -> keyboard_readings_include_keycap_and_extended_scan_code FAILED at gameinput.rs:1322. dead_key: false -> the test still PASSED.

Review findings:

  1. Test coverage gap: the dead-key and unshifted-é assertions only run when the host layout is exactly 0000040C (French AZERTY). On any other layout the dead-key path has no assertion at all, as the surviving mutation above shows, so CI and most developer machines never exercise it.
  2. The code_point == 'A' assertion is also layout dependent: it would fail on a layout where VK_A maps to a non-Latin glyph (for example Russian or Greek). A synthetic layout-independent check, or skipping unless the layout is Latin, would be safer.
  3. Nit: the doc comment /// The foreground window is one of ours ... now sits above readings instead of focused_layout (the function it described).
    No production blocker found: the layout used is the foreground window thread's (falling back to the calling thread's for scripted keys with no focus), and the dead-key bit and low word are taken from MAPVK_VK_TO_CHAR as documented.

Not tested additionally: the AZERTY branch itself (not installed here).

Not tested: physical GPU, retail title/game behavior, release build (debug profile only).

AI disclosure: Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173409186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173409186). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:15:40Z. --- Independent WARP/CPU verification for head 9ff50e868e51ae374952c46d3f90224aa79f861d against origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment. Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1` set (WARP only, no physical GPU); no game files. `CARGO_TARGET_DIR=D:\victory-warp-2741-target`. Tested commit: the PR head itself, which is exactly one commit on top of `origin/main` (merge-base = `origin/main`, so no temporary merge was needed). Host keyboard layouts: de-CH, en-GB (a Windows API test, so it ran on the real host layout; no layout was switched). Commands/results: - Baseline (origin/main): `cargo test --locked -p victory-hle` — lib 146 passed, 0 failed; other binaries pass. `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` — pass. - PR: `cargo test --locked -p victory-hle --lib keyboard_readings` — 1/1 passed. `cargo test --locked -p victory-hle` — lib 147 passed (+1), 0 failed; and with `--features diagnostics` also lib 147 passed, 0 failed. Clippy `--all-targets -- -D warnings` passes with and without `--features diagnostics`. - Negative controls (restored, tree clean): `code_point: 0` (the pre-PR value) -> `keyboard_readings_include_keycap_and_extended_scan_code` FAILED at gameinput.rs:1322. `dead_key: false` -> the test still PASSED. Review findings: 1. Test coverage gap: the dead-key and unshifted-é assertions only run when the host layout is exactly 0000040C (French AZERTY). On any other layout the dead-key path has no assertion at all, as the surviving mutation above shows, so CI and most developer machines never exercise it. 2. The `code_point == 'A'` assertion is also layout dependent: it would fail on a layout where VK_A maps to a non-Latin glyph (for example Russian or Greek). A synthetic layout-independent check, or skipping unless the layout is Latin, would be safer. 3. Nit: the doc comment `/// The foreground window is one of ours ...` now sits above `readings` instead of `focused_layout` (the function it described). No production blocker found: the layout used is the foreground window thread's (falling back to the calling thread's for scripted keys with no focus), and the dead-key bit and low word are taken from `MAPVK_VK_TO_CHAR` as documented. Not tested additionally: the AZERTY branch itself (not installed here). Not tested: physical GPU, retail title/game behavior, release build (debug profile only). AI disclosure: Claude Code (Claude Sonnet 5.5).
fuzeofficlal commented 2026-11-25 21:03:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:21:59Z.


Reviewed and verified 9ff50e86 on Windows 11 against main (13f91ca).

Code review

  • focused_layout() cleanly guards foreground ownership (process == GetCurrentProcessId()) and skips physical keyboard polling when unfocused or focused in another process, while VICTORY_KEYS under diagnostics still falls back to GetKeyboardLayout(0).
  • Using MapVirtualKeyExW (MAPVK_VK_TO_VSC_EX and MAPVK_VK_TO_CHAR) is safe with respect to system dead-key state (unlike unflagged ToUnicodeEx, it does not mutate kernel keyboard state, has no buffer truncation or surrogate issues, and handles hkl == 0 gracefully).
  • Design tradeoff to note: MAPVK_VK_TO_CHAR reports unshifted keycap glyphs (e.g., uppercase letters, no Shift/AltGr punctuation or non-BMP glyphs), whereas #656 (which conflicts in the same gameinput.rs hunk) uses ToUnicodeEx(..., wFlags=4) for shifted/composed characters.

Verification (Windows 11, rustc 1.98.1 MSVC)

  • cargo test -p victory-hle --lib --locked (6 consecutive full parallel runs): 6/6 passed (147 passed, 0 failed).
  • cargo test -p victory-hle --lib --features diagnostics --locked -- modules::gameinput::: 10 passed, 0 failed (including keyboard_readings_include_keycap_and_extended_scan_code).
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings (default & --all-features): 0 warnings; cargo xtask policy: 184 files ok.
  • Clean git merge-tree against 13f91ca, #1430, #2715, and #2717; conflicts with #656.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173562803 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173562803). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:21:59Z. --- Reviewed and verified `9ff50e86` on Windows 11 against `main` (`13f91ca`). ### Code review - `focused_layout()` cleanly guards foreground ownership (`process == GetCurrentProcessId()`) and skips physical keyboard polling when unfocused or focused in another process, while `VICTORY_KEYS` under `diagnostics` still falls back to `GetKeyboardLayout(0)`. - Using `MapVirtualKeyExW` (`MAPVK_VK_TO_VSC_EX` and `MAPVK_VK_TO_CHAR`) is safe with respect to system dead-key state (unlike unflagged `ToUnicodeEx`, it does not mutate kernel keyboard state, has no buffer truncation or surrogate issues, and handles `hkl == 0` gracefully). - Design tradeoff to note: `MAPVK_VK_TO_CHAR` reports unshifted keycap glyphs (e.g., uppercase letters, no Shift/AltGr punctuation or non-BMP glyphs), whereas `#656` (which conflicts in the same `gameinput.rs` hunk) uses `ToUnicodeEx(..., wFlags=4)` for shifted/composed characters. ### Verification (Windows 11, `rustc 1.98.1` MSVC) - `cargo test -p victory-hle --lib --locked` (6 consecutive full parallel runs): **6/6 passed** (`147 passed, 0 failed`). - `cargo test -p victory-hle --lib --features diagnostics --locked -- modules::gameinput::`: **10 passed, 0 failed** (including `keyboard_readings_include_keycap_and_extended_scan_code`). - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (default & `--all-features`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - Clean `git merge-tree` against `13f91ca`, `#1430`, `#2715`, and `#2717`; conflicts with `#656`.
Marvisak commented 2026-11-26 00:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:27:13Z.


Automated triage for the maintainers. In crates/victory-hle/src/modules/gameinput.rs, key_state now fills code_point and dead_key from MapVirtualKeyExW(MAPVK_VK_TO_CHAR) with the focused window's layout. The API use looks right, but a few things need changing first. (1) The removed comment said the title reads only scan codes and virtual keys. Please say where these fields are read, and give evidence for what the console reports in codePoint: MAPVK_VK_TO_CHAR gives the unshifted keycap glyph (uppercase 'A' for the A key), which is not obviously the console's value. (2) keyboard_readings_include_keycap_and_extended_scan_code asserts code_point == 'A' on the host layout, so it fails on non-Latin layouts (for example Russian or Greek). The dead-key assertion runs only on French AZERTY, so most machines and CI never check it. Please make the test independent of the layout, for example by loading a known layout or skipping when the layout does not match. (3) The doc comment /// The foreground window is one of ours ... now sits above readings instead of focused_layout. CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177580149 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7177580149). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:27:13Z. --- <!-- victory-triage v1 head=9ff50e868e51ae374952c46d3f90224aa79f861d verdict=needs-work at=2026-11-25T23:27:03Z --> Automated triage for the maintainers. In `crates/victory-hle/src/modules/gameinput.rs`, `key_state` now fills `code_point` and `dead_key` from `MapVirtualKeyExW(MAPVK_VK_TO_CHAR)` with the focused window's layout. The API use looks right, but a few things need changing first. (1) The removed comment said the title reads only scan codes and virtual keys. Please say where these fields are read, and give evidence for what the console reports in `codePoint`: `MAPVK_VK_TO_CHAR` gives the unshifted keycap glyph (uppercase 'A' for the A key), which is not obviously the console's value. (2) `keyboard_readings_include_keycap_and_extended_scan_code` asserts `code_point == 'A'` on the host layout, so it fails on non-Latin layouts (for example Russian or Greek). The dead-key assertion runs only on French AZERTY, so most machines and CI never check it. Please make the test independent of the layout, for example by loading a known layout or skipping when the layout does not match. (3) The doc comment `/// The foreground window is one of ours ...` now sits above `readings` instead of `focused_layout`. CI: `check` passing. --- _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/2757:upstream-pr/2757'
git switch 'upstream-pr/2757'

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/2757'
git switch 'upstream-pr/2757'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2757'
git switch 'upstream-pr/2757'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2757'
git switch 'main'
git merge --squash 'upstream-pr/2757'
git switch 'main'
git merge --ff-only 'upstream-pr/2757'
git switch 'main'
git merge 'upstream-pr/2757'
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!2755
No description provided.