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

Open
github-bot wants to merge 1 commit from github-bot/gh-2757 into main AGit
Owner

@⁠maxence468 on GitHub · 2026-11-25 19:48 UTC · original
maxence468:input/layout-key-readings → main · +56 −13 · 1 files · 1 commits · open

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.

**@⁠maxence468** on GitHub · 2026-11-25 19:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757) `maxence468:input/layout-key-readings` → `main` · +56 −13 · 1 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:28 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:07 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173229211) 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.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 20:13 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-25 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173364593) 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:15 UTC · original

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).

**@⁠oni-swr** on GitHub · 2026-11-25 20:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173409186) 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:21 UTC · original

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7173562803) 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`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:27 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2757#issuecomment-7177580149) <!-- 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2757/head:github-bot/gh-2757'
git switch 'github-bot/gh-2757'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2757'
git switch 'github-bot/gh-2757'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2757'
git switch 'github-bot/gh-2757'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2757'
git switch 'main'
git merge --squash 'github-bot/gh-2757'
git switch 'main'
git merge --ff-only 'github-bot/gh-2757'
git switch 'main'
git merge 'github-bot/gh-2757'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2757
No description provided.