Skip to content

gameinput: keyboard and mouse devices and readings (carries #2413 forward on current main) - #8283

Open
tedin7 wants to merge 4 commits into
ItsNotRexed:mainfrom
tedin7:c2-gameinput-keyboard
Open

tedin7 wants to merge 4 commits into
ItsNotRexed:mainfrom
tedin7:c2-gameinput-keyboard

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

What

GameInput keyboard and mouse devices and readings (RT-159), merged with current main. With LEONIDA_KEYBOARD_MOUSE set, the shim shows a Keyboard (Leonida) and a Mouse (Leonida) device. Their readings carry the keyboard or mouse kind only.

This PR resolves the conflicts with main in runtime/shims/gameinput.cpp and docs/gameinput.md, keeping both sides: main's raw device reports (RT-175), force feedback and haptic motors, and the keyboard and mouse readings. It also adds tests for the three keyboard calls the executable makes.

Why

The executable reads the keyboard through GameInput (#7637): GetCurrentReading(Keyboard) once, GetNextReading(Keyboard) once and RegisterDeviceCallback(Keyboard, Connected) once. Without keyboard devices the shim answers all three with nothing.

Tested

gameinput_test, cross-built with clang-cl and run under Wine (SDL3 fetched with -DLEONIDA_SDL3_FETCH=ON): 376 checks, 0 failures. This includes the focus-loss reading HRESULT checks:

  • GetCurrentReading(Keyboard) with no key held is an empty reading.
  • GetNextReading(Keyboard) with no key pressed is GAMEINPUT_E_READING_NOT_FOUND.
  • With a fake Enter (VK_RETURN), GetNextReading(Keyboard) returns one key with scan code 0x1C, and nothing follows it.
  • RegisterDeviceCallback(Keyboard, Connected) is S_OK and hears the keyboard once (not the mouse). The Gamepad callback does not hear it.

Keyboard and mouse polling continues when SDL gamepad initialization fails; the harness has no gamepad initialization failure hook, so that failure path was not exercised. Key translation uses the foreground window thread layout. Focus-loss tests now require successful readings.

No existing S_OK became an error in the test. I did not run the unmerged head of #2413 for a before number.

Builds on #2413 by @TheHoracio (their commits are kept; merged with current main and conflicts resolved)

@ItsNotRexed: an exe PR, as you asked.

Claim: #8186 (comment)

TheHoracio and others added 4 commits November 22, 2026 21:29
IGameInputReading returned nothing for keyboard and mouse, so a title that
reads them through GameInput got no input on PC. With
LEONIDA_KEYBOARD_MOUSE=1|always the shim connects a keyboard device and a
mouse device next to the pads. Their readings carry GameInputKindKeyboard or
GameInputKindMouse only: GetKeyCount/GetKeyState list the held keys (virtual
key, scan code, character, dead-key flag; up to 16), GetMouseState the
buttons and the cursor's movement summed into relative positions. Keys and
buttons come from GetAsyncKeyState with the keyboard pad's focus rule.

They stay out of the pad list (no SDL, rumble, battery or player slot), and
every reading search, enumeration, aggregate and FindDeviceFromId covers
them; a search with no device now filters by kind, so a gamepad query never
answers with a keyboard reading. The v0 structs are declared in
gameinput_abi.h with static_asserts on their layout.

gameinput_test: 21 checks with fake keys, focus and cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, 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>
@thehollowedone

Copy link
Copy Markdown

Independent native Windows check of 83d80451 with MSVC 19.44.35230 x64 and SDL3 3.4.20. The stock gameinput CTest passed all 376 checks.

Synthetic Enter produced one key with scan code 0x1C, then READING_NOT_FOUND. On focus loss the keyboard reading was empty and cursor movement was ignored. The keyboard callback reported exactly one connected keyboard and excluded the mouse. The gamepad callback excluded the keyboard.

The fixture supplied synthetic input with physical controller backends disabled. AI-assisted.

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, SDL3 3.4.20 via -DLEONIDA_SDL3_FETCH=ON. GPU (not used): NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124. No physical controller attached.

Head 83d804510, merged locally with current main 47428cc22 (clean merge).

Target / test Result
gameinput_test, gta6rt build, no new warnings in gameinput*.{cpp,h}
gameinput_test.exe exit 0, 376 checks, 0 failures (96 of the PASS lines are keyboard/mouse/key checks)

Code-reading notes (not blocking):

  • With LEONIDA_KEYBOARD_MOUSE on, GetCurrentReading(GameInputKindUnknown, nullptr, ...) now returns the newest reading from any device. Every cursor movement pushes a mouse reading, so a title that asks for "any" kind gets mouse readings ahead of pad readings. The explicit-kind paths filter by supportedInput, so GameInputKindGamepad still only returns pads, as the new comment says.
  • Mouse motion is the cursor delta (g_cursor_pos), so it stops at the screen edge, and a title that clips or recentres the cursor gets zero or reversed deltas. Raw input (WM_INPUT) would avoid that. The VERIFY comment covers device identity but not this.
  • GetKeyState copies n * sizeof(GameInputKeyState) into a void* without checking count against the struct the caller sized. That matches the public API contract, so it's only noted.

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.

4 participants