startup_stubs: add GameInput keyboard readings and GetPreviousReading history #1429
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1436"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:30:42Z.
Summary
Implements
W2-1insrc/startup_stubs/gameinput.cpp(GameInput.dllstand-in):GameInputKindKeyboard(0x10) support with a distinct virtual keyboardIGameInputDevice(the_keyboard_device,GameInputDeviceInfowithsupportedInput = GameInputKindKeyboard), enumerated viaRegisterDeviceCallbackand resolvable viaFindDeviceFrom*.IGameInputReading::GetKeyCount(vtable slot 14) andIGameInputReading::GetKeyState(vtable slot 15) using the public v0GameInputKeyState12-byte layout (scanCode,codePoint,virtualKey,isDeadKey), samplingX2W_INPUT_KEYS(hex VK list) and focusedGetAsyncKeyState.src/startup_stubs/gameinput.cppsoIGameInput::GetPreviousReading(slot 6) andIGameInput::GetNextReading(slot 5) walk reading sequences cleanly (GAMEINPUT_E_READING_NOT_FOUND/GAMEINPUT_E_REFERENCE_READING_TOO_OLD), while preserving 100% of existing gamepad andX2W_INPUT_PRESS/X2W_INPUT_SCRIPTbehavior.tests/startup_gameinput_keys.cpp(startup_gameinput_keysCTest target inCMakeLists.txt) covering keyboard readings,GetKeyCount/GetKeyState,GetPreviousReading/GetNextReadinghistory chain, combined keyboard+gamepad readings, and negative controls.Verification
git diff --checkpython3 tests/docs_links_check.pypython3 tests/bidi_controls_check.pypython3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py preflight /root/wt/x2w-h-gameinput(VERDICT: OK)AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:45:32Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
35a913a4d5ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:38Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:41Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:44Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:47Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:35:37Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
35a913a4d523527886ca567a22b1e7a8c14cde0b:--preset dev):cmake --build --preset dev --target startup_gameinput_keys startup_stub_gameinput -- -j 6):3.83s(configure1.78s)ctest --preset dev -R '^startup_gameinput_keys$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.13s:startup_gameinput_keys0.06s)/O2(--preset release):cmake --build --preset release --target startup_gameinput_keys startup_stub_gameinput -- -j 6):1.09s(configure1.68s)ctest --preset release -R '^startup_gameinput_keys$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.12s:startup_gameinput_keys0.03s)sccache: 0/4 hits; wall14.4sImported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:35:46Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
35a913aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:45:33Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 522When a caller uses v0
FindDeviceFromPlatformHandle,build()routes slot 18 to this handler, just as it does slots 16–19. A Win32 handle is an opaque numeric value, not a pointer to a 32-byte device ID, so the newmemcmpdereferences the handle and causes an access violation. The parent handler did not dereference this argument; an isolated before/after harness succeeds against the parent and crashes against this change with a handle-shaped value of0x4. Give the differently typed lookup methods separate handlers, returning an appropriate failure for unsupported lookups rather than treating every argument as an ID.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:45:33Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 459For a gamepad-only caller, changing only
X2W_INPUT_KEYSadvances the shared sequence incapture_current(), and this lookup then returns that keyboard-only change as a new gamepad reading. An isolated comparison with the parent reproducesS_OKand an advanced gamepad sequence despite identical gamepad state; after enough keyboard-only changes, the same gamepad reference instead producesreading_too_old.GetPreviousReadinghas the same unfiltered traversal. Preserve device/kind-specific history, or record which device changed and skip nonmatching entries, rather than relabeling every adjacent global snapshot as the requested input.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:45:33Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 211With a focused window and only left Shift held, both
GetAsyncKeyState(VK_SHIFT)andGetAsyncKeyState(VK_LSHIFT)report the key as down. This loop appends both becausepush_vkdeduplicates only identical virtual-key values, so one physical key becomes twoKeyStateentries; Ctrl and Alt have the same problem. This makes key counts and physical-key/chord tracking incorrect. Poll only the side-specific modifier codes, or normalize the generic aliases before appending them.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:45:33Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 194For an extended key such as Left Arrow (
VK_LEFT, also injectable withX2W_INPUT_KEYS=25),MAPVK_VK_TO_VSCreturns0x4Bwithout theE0prefix, making its scan code indistinguishable from keypad 4. Right Ctrl and right Alt similarly lose their extended prefixes. Scan-code-based navigation and modifier bindings therefore receive the wrong key identity; the existing keyboard fixture intests/cpu/gameinput_provider.cppexplicitly represents Left Arrow as0xE04B. Use the extended scan-code mapping and preserve the prefix in the returnedKeyState.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:38Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 522Fixed in
054c159d: separate handlers: FindDeviceFromId (slot 16) compares IDs; FindDeviceFromPlatformHandle (slot 18) never dereferences the handle and returns device_not_found; Object/PlatformString keep the old behavior. Test: handle 0x4 + id lookup.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:41Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 459Fixed in
054c159d: history entries now record which device changed; GetNextReading/GetPreviousReading skip entries that did not change the requested device/kind. Test: keyboard-only changes invisible to gamepad callers and vice versa.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:44Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 211Fixed in
054c159d: VK_SHIFT/VK_CONTROL/VK_MENU aliases are never reported; only side-specific keys remain. Test: X2W_INPUT_KEYS=10,11,12,A0,A2 yields 2 keys.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:50:47Z.
Code review location:
src/startup_stubs/gameinput.cpp; line 194Fixed in
054c159d: scan codes use MAPVK_VK_TO_VSC_EX and the navigation cluster is prefixed with E0 (Left Arrow 0xE04B vs Numpad4 0x4B, RCtrl 0xE01D, RAlt 0xE038). Test added.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:09:11Z.
Review: CHANGES_REQUESTED
The device lookup split and key fixes address the earlier findings. One history compatibility case remains on
054c159d. GetSequenceNumber still returns the shared event counter for every kind, so a keyboard-only change increments a gamepad reading's number, even though Next now skips that entry. The shared 64-entry ring also lets only keyboard events age out an otherwise current gamepad reference. Please keep an internal ordering sequence separate from per-kind sequence/history retention (or limit the first PR to keyboard sampling). Add one control showing the existing gamepad sequence is unchanged after repeated keyboard-only reads. GameInput's documented sequence is per kind: https://learn.microsoft.com/en-us/xbox/gdk/docs/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getsequencenumberImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:36:55Z.
Review: APPROVED
Windows Release startup_gameinput_keys passed on this revision. From a gamepad event, the previous keyboard result is the nearest earlier keyboard event. From that keyboard event, previous steps back one entry. Preserved the per-kind eviction control. Microsoft GameInput stream contract: https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:20:52Z.
@R0Y00 Fixed in
9e056e3c(sequence change in06edf01a): each reading now keeps an internal ordering counter separate from the per-kind sequence numbers. GetSequenceNumber returns the gamepad or keyboard sequence for the requested kind, and each kind has its own 64-entry retention ring, so keyboard events can no longer advance a gamepad sequence or age out a gamepad reference. Next/Previous pick the nearest entry of the wanted kind(s) by the internal order. Tests added in startup_gameinput_keys: the gamepad sequence is unchanged after repeated keyboard-only reads, and a gamepad reference survives 100 keyboard-only events (GetNextReading is not_found, not too_old). Win2025 Debug and Release /O2: startup_gameinput_keys 1/1 passed.upstream-sync referenced this pull request2026-11-24 16:03:19 +00:00