input(macos): add PS/2 scan codes, full keyboard/modifier mapping, and NSEvent tests #9

Manually merged
github merged 2 commits from gh-pr/9/head into gh-pr/9/base 2026-11-26 14:42:22 +00:00
Owner

@⁠claytonblythe on GitHub · 2026-11-26 08:44 UTC · original
claytonblythe:feat/macos-live-keyboard → main · +310 −16 · 2 files · 2 commits · merged 2026-11-26 09:03 UTC

What this changes

Rebased onto main (c96c82a, after native/keyboard landed). Extends live macOS keyboard input (#1) with:

  • PS/2 Set-1 scan codes (crates/victory-hle/src/modules/gameinput.rs): Populates KeyState::scan_code (including 0xE0 extended prefixes matching MapVirtualKeyW(..., MAPVK_VK_TO_VSC_EX)) instead of leaving scan_code: 0.
  • Full keyboard & L/R modifier coverage (apps/victory/src/window.rs): Maps remaining alphanumeric keys, digits 0–9, F1–F12, Home/End/PageUp/PageDown/Forward Delete, punctuation, and NSEventTypeFlagsChanged L/R Shift/Control/Option modifiers.
  • End-to-end tests:
    • real_nsevents_update_live_keys_and_ignore_non_key_events: exercises key_event with real synthetic AppKit NSEvent objects (KeyDown, KeyUp, Cmd+Q, FlagsChanged, and NSApplicationDefined non-key events so c96c82a cannot regress).
    • live_keys_report_ps2_scan_codes_through_hub_readings: exercises set_live_key -> Hub::poll() -> IGameInput::GetCurrentReading for both KEYBOARD_KIND (verifying scan_code) and GAMEPAD_KIND (FALLBACK).

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory window (2/2 passed, including real NSEvent test)
  • cargo test --target x86_64-apple-darwin -p victory-hle gameinput (10/10 passed, including COM Hub scan-code test)
  • cargo xtask policy (356 files ok)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (0 warnings)
  • Ran the game (tested end-to-end with synthetic AppKit NSEvent objects and the GameInput COM Hub)

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (N/A)
  • New diagnostics are behind a VICTORY_* variable and documented (N/A)
**@⁠claytonblythe** on GitHub · 2026-11-26 08:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/9) `claytonblythe:feat/macos-live-keyboard` → `main` · +310 −16 · 2 files · 2 commits · merged 2026-11-26 09:03 UTC ## What this changes Rebased onto `main` (`c96c82a`, after `native/keyboard` landed). Extends live macOS keyboard input (#1) with: - **PS/2 Set-1 scan codes (`crates/victory-hle/src/modules/gameinput.rs`)**: Populates `KeyState::scan_code` (including `0xE0` extended prefixes matching `MapVirtualKeyW(..., MAPVK_VK_TO_VSC_EX)`) instead of leaving `scan_code: 0`. - **Full keyboard & L/R modifier coverage (`apps/victory/src/window.rs`)**: Maps remaining alphanumeric keys, digits `0`–`9`, F1–F12, Home/End/PageUp/PageDown/Forward Delete, punctuation, and `NSEventTypeFlagsChanged` L/R Shift/Control/Option modifiers. - **End-to-end tests**: - `real_nsevents_update_live_keys_and_ignore_non_key_events`: exercises `key_event` with real synthetic AppKit `NSEvent` objects (`KeyDown`, `KeyUp`, `Cmd+Q`, `FlagsChanged`, and `NSApplicationDefined` non-key events so `c96c82a` cannot regress). - `live_keys_report_ps2_scan_codes_through_hub_readings`: exercises `set_live_key` -> `Hub::poll()` -> `IGameInput::GetCurrentReading` for both `KEYBOARD_KIND` (verifying `scan_code`) and `GAMEPAD_KIND` (`FALLBACK`). ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory window` (2/2 passed, including real `NSEvent` test) - [x] `cargo test --target x86_64-apple-darwin -p victory-hle gameinput` (10/10 passed, including COM `Hub` scan-code test) - [x] `cargo xtask policy` (356 files ok) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (0 warnings) - [ ] Ran the game (tested end-to-end with synthetic AppKit `NSEvent` objects and the `GameInput` COM `Hub`) ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (N/A) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (N/A)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:42:21 +00:00
github manually merged commit 071f16027e into gh-pr/9/base 2026-11-26 14:42:22 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 08:47 UTC · original

Thanks for this, it's careful work: reading the event type before keyCode, the modifier handling and the real NSEvent tests are all good.

I'm not merging it as is, though. While it was open, live keyboard input landed on main (c96c82a) in the same two files, so this PR now conflicts, and much of it duplicates what's there. It also hasn't been run against the game yet, and CI hasn't run on it.

The parts of yours that main doesn't have are worth keeping: the GameInput keyboard device (scan codes via vk_to_scan_code) and FlagsChanged for Shift/Control/Option. If you'd like, rebase onto main and keep only those, on top of the existing key mapping (Enter/Space = A, Esc/Backspace = B, Tab = Menu, see the README), and I'll review it again.

What would help most next is real controllers: I've opened #10 for wiring the Game Controller framework into GameInput. You already know this part of the code better than anyone else outside the project, so it would be great if you took it on. Comment on #10 if you're picking it up.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/9#issuecomment-7187022764) Thanks for this, it's careful work: reading the event type before `keyCode`, the modifier handling and the real `NSEvent` tests are all good. I'm not merging it as is, though. While it was open, live keyboard input landed on `main` (c96c82a) in the same two files, so this PR now conflicts, and much of it duplicates what's there. It also hasn't been run against the game yet, and CI hasn't run on it. The parts of yours that `main` doesn't have are worth keeping: the GameInput **keyboard device** (scan codes via `vk_to_scan_code`) and `FlagsChanged` for Shift/Control/Option. If you'd like, rebase onto `main` and keep only those, on top of the existing key mapping (Enter/Space = A, Esc/Backspace = B, Tab = Menu, see the README), and I'll review it again. What would help most next is **real controllers**: I've opened #10 for wiring the Game Controller framework into `GameInput`. You already know this part of the code better than anyone else outside the project, so it would be great if you took it on. Comment on #10 if you're picking it up.
Author
Owner

@⁠claytonblythe on GitHub · 2026-11-26 08:50 UTC · original

Thanks for the review! I had just rebased onto main (c96c82a) right as your comment came in — 4383783 is now conflict-free and keeps only the additions on top of main (vk_to_scan_code PS/2 Set-1 scan codes, full keyboard + FlagsChanged Shift/Control/Option handling, and the real NSEvent + COM Hub tests). Will also test it against the real game once my setup finishes, and I'm claiming #10 next.

**@⁠claytonblythe** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/9#issuecomment-7187089028) Thanks for the review! I had just rebased onto `main` (`c96c82a`) right as your comment came in — `4383783` is now conflict-free and keeps only the additions on top of `main` (`vk_to_scan_code` PS/2 Set-1 scan codes, full keyboard + `FlagsChanged` Shift/Control/Option handling, and the real `NSEvent` + COM `Hub` tests). Will also test it against the real game once my setup finishes, and I'm claiming #10 next.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 08:57 UTC · original · approved these changes

Reviewed: the scan codes, full key mapping and FlagsChanged handling sit cleanly on top of main. Tests and Windows clippy pass locally on the merged result. Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 08:57 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/9#pullrequestreview-6071071236) · **approved these changes** Reviewed: the scan codes, full key mapping and FlagsChanged handling sit cleanly on top of main. Tests and Windows clippy pass locally on the merged result. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.