Skip to content

GameInput: keyboard and mouse devices behind LEONIDA_KEYBOARD_MOUSE (RT-159) - #2426

Closed
justr4mzi wants to merge 1 commit into
ItsNotRexed:mainfrom
justr4mzi:rt-159-keyboard-mouse
Closed

justr4mzi wants to merge 1 commit into
ItsNotRexed:mainfrom
justr4mzi:rt-159-keyboard-mouse

Conversation

@justr4mzi

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-159 (#2300)

What and why

IGameInputReading returned nothing for the keyboard and the mouse (docs/gameinput.md API table), so a title that reads them through GameInput directly gets no input on PC. With LEONIDA_KEYBOARD_MOUSE=1 (or always) the shim now connects one GameInput keyboard device and one mouse device. Off by default, like the keyboard pad.

  • GetKeyCount / GetKeyState: the keys that are down, lowest virtual-key code first, at most 16 (maxSimultaneousKeys). Generic Shift/Ctrl/Alt are left out, their left/right keys are reported. Scan code from MapVirtualKeyW(MAPVK_VK_TO_VSC_EX), glyph from MAPVK_VK_TO_CHAR (dead-key bit -> isDeadKey).
  • GetMouseState: left, right, middle, X1, X2, and positionX/Y as the cursor movement summed since connect (GameInput positions are cumulative, the title takes the difference).
  • Device info with keyboardInfo / mouseInfo (layout id, GetKeyboardType, F1-F24, five buttons), family GameInputFamilyHid, fixed ids, device and reading callbacks for their kinds, history (GetNext/PreviousReading), aggregate devices.
  • Same sources, test seams and focus rules as the keyboard pad (GetAsyncKeyState, GetCursorPos; with 1 nothing counts while another app has focus, no mouse jump when focus returns).
  • gameinput_abi.h: v0 GameInputKeyState, GameInputMouseState, GameInputKeyboardInfo, GameInputMouseInfo and the two enums, with static_asserts on size and offsets.

Gamepad behaviour is unchanged: gamepad-kind queries and callbacks never see the two devices, connected_count() / output_state() count gamepads only, and a gamepad reading answers exactly the kinds it did before.

Not done (written in docs/gameinput.md): the wheel (no window or message loop, so wheelX/Y stay 0 and hasWheelX/Y is false; raw input on a message-only window would give the wheel and unaccelerated counts), and cursor movement stops at the screen edge, as for the keyboard pad. VERIFY items added: the family, the scan-code convention, the key order and the v0 layouts, which come from Microsoft's docs and were not compiled against the public v0 header.

Tested

  • gameinput_test: new test_keyboard_mouse (37 checks on fake keys, focus and cursor). Whole test: 238 checks, 0 failures, before the change 201/0, run three times.
  • Built with MinGW-w64 GCC 13 (-Wall -Wextra, no warnings) against the pinned SDL3 3.4.20, run under Wine 9.0 on Linux. No GPU involved. Not built with MSVC: please let CI check the /W4 build.
  • gameinput_probe still builds.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

…RT-159)

IGameInputReading returned nothing for the keyboard and the mouse, so a title
that reads them directly got no input on PC. With LEONIDA_KEYBOARD_MOUSE=1
(or always) the shim connects one GameInput keyboard device and one mouse
device:

- GetKeyCount/GetKeyState: the keys that are down, by virtual-key code, at
  most 16, left/right modifiers instead of the generic ones, with the scan
  code and glyph from MapVirtualKeyW.
- GetMouseState: five buttons, and positionX/Y as summed cursor movement
  (GameInput positions are cumulative). No wheel yet: hasWheelX/Y false.
- Device info with keyboardInfo/mouseInfo (v0 layouts, static_asserts),
  device and reading callbacks for their kinds, history, aggregate devices.
- Same sources and focus rules as the keyboard pad (GetAsyncKeyState,
  GetCursorPos, the existing test seams). Off by default.

Gamepad behaviour is unchanged: gamepad-kind queries and callbacks never see
the two devices, and connected_count()/output_state() count gamepads only.
@justr4mzi

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2413, which claimed RT-159 first in #2300 and was tested on Windows/MSVC with the ABI checked against the real v0 header. Sorry for the overlap, I missed the claim. I'll test #2413 with this branch's independent checks instead and report there.

@Kam471

Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent review on Windows 11: built with MSVC 19.44 + SDL3 3.4.20.

cmake --build gi-build-2426 --target gameinput_test
ctest --test-dir gi-build-2426 -R ^gameinput$

238 checks, 0 failures (37 new); CTest 1/1.

This is the more complete of the two RT-159 implementations: real layout/keyCount, 24 F-keys, sampleRate = 500, per-kind callbacks, history, aggregate keyboard, always, reconnect identity, and a snapshot that compares every key field (so a layout change produces a new reading). The Device::Type insertion is more invasive than #2413's State::kbm, but the remaining connected uses keep player = -1, so pad slots are unchanged.

One nit: the API table still lists CreateAggregateDevice as unimplemented while the new section and test use it — move that row.

Recommendation: keep #2426, close #2413 as superseded. No blocker from my side.

TheHoracio added a commit to TheHoracio/Leonida that referenced this pull request Nov 22, 2026
…, non-null nativeLanguage, full key compare

From Kam471's review of ItsNotRexed#2413 and @justr4mzi's ItsNotRexed#2426:
- keyboardInfo.layout is the active KLID (GetKeyboardLayoutNameW), keyCount the reportable virtual keys with a
  scan code, functionKeyCount GetKeyboardType(2) (12 if Windows doesn't say).
- keyboardInfo.nativeLanguage points at an empty GameInputString instead of null, so a title reading it does not
  dereference null.
- mouseInfo.sampleRate is 500: one sample per 2 ms poll_thread() pass.
- A held key whose scan code, character or dead-key flag changes (a layout switch) is a new reading: same_keys
  compares every field, not only virtualKey.

gameinput_test: 226 checks, 0 failures (4 new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheHoracio added a commit to TheHoracio/Leonida that referenced this pull request Nov 22, 2026
…, non-null nativeLanguage, full key compare

From Kam471's review of ItsNotRexed#2413 and @justr4mzi's ItsNotRexed#2426:
- keyboardInfo.layout is the active KLID (GetKeyboardLayoutNameW), keyCount the reportable virtual keys with a
  scan code, functionKeyCount GetKeyboardType(2) (12 if Windows doesn't say).
- keyboardInfo.nativeLanguage points at an empty GameInputString instead of null, so a title reading it does not
  dereference null.
- mouseInfo.sampleRate is 500: one sample per 2 ms poll_thread() pass.
- A held key whose scan code, character or dead-key flag changes (a layout switch) is a new reading: same_keys
  compares every field, not only virtualKey.

gameinput_test: 226 checks, 0 failures (4 new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheHoracio added a commit to TheHoracio/Leonida that referenced this pull request Nov 22, 2026
…, non-null nativeLanguage, full key compare

From Kam471's review of ItsNotRexed#2413 and @justr4mzi's ItsNotRexed#2426:
- keyboardInfo.layout is the active KLID (GetKeyboardLayoutNameW), keyCount the reportable virtual keys with a
  scan code, functionKeyCount GetKeyboardType(2) (12 if Windows doesn't say).
- keyboardInfo.nativeLanguage points at an empty GameInputString instead of null, so a title reading it does not
  dereference null.
- mouseInfo.sampleRate is 500: one sample per 2 ms poll_thread() pass.
- A held key whose scan code, character or dead-key flag changes (a layout switch) is a new reading: same_keys
  compares every field, not only virtualKey.

gameinput_test: 226 checks, 0 failures (4 new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants