diff options
| author | Cozma <65982369+Cozmaaa@users.noreply.github.com> | 2026-11-22 06:05:38 +0200 |
|---|---|---|
| committer | Cozma <65982369+Cozmaaa@users.noreply.github.com> | 2026-11-22 06:05:38 +0200 |
| commit | 5097ea041aef13bbb6b11c7f6f92dd2ee515bc53 (patch) | |
| tree | c77a10ab1d8b67175ecdf5693b0d74c70b0953d9 /docs/gameinput.md | |
| parent | 4a36bb19979b611f525d027f92e0fefad1626546 (diff) | |
GameInput shim: keyboard pad (LEONIDA_KEYBOARD_PAD)
The title reads gamepads only, so keys reach it as one more pad: an SDL
virtual gamepad whose buttons are pressed from GetAsyncKeyState on each
poll. It goes through open_pad/read_pad like a real controller (device
object, player slot, readings, callbacks, UI navigation) and reports no
motors.
Arrows d-pad, Enter A, Backspace B, X X, Y Y, Q/E shoulders, Esc Menu,
Tab View. Off by default; =1 reads keys only while a window of this
process is in the foreground and releases everything on focus loss,
=always ignores focus (console tools). Sticks and triggers stay at rest.
gameinput_test drives it through set_keyboard_source with fake keys and
focus: 31 new checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs/gameinput.md')
| -rw-r--r-- | docs/gameinput.md | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md index 0096285b2..6b3230ac9 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -62,6 +62,37 @@ controller-button array (`GetControllerButtonState`, indexed in SDL's `SDL_Gamep | |||
| 62 | - Player LEDs (and SDL's default lightbar colour) follow connection order: the first pad is player 1, and a pad | 62 | - Player LEDs (and SDL's default lightbar colour) follow connection order: the first pad is player 1, and a pad |
| 63 | plugged in later takes the lowest free slot. | 63 | plugged in later takes the lowest free slot. |
| 64 | 64 | ||
| 65 | ## Keyboard pad | ||
| 66 | |||
| 67 | The title reads gamepads only, so keyboard input has to arrive as a gamepad. With `LEONIDA_KEYBOARD_PAD` set, the | ||
| 68 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on | ||
| 69 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, | ||
| 70 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by | ||
| 71 | default. | ||
| 72 | |||
| 73 | | key | button | | ||
| 74 | |---|---| | ||
| 75 | | arrow keys | d-pad | | ||
| 76 | | Enter | `A` | | ||
| 77 | | Backspace | `B` | | ||
| 78 | | X | `X` | | ||
| 79 | | Y | `Y` | | ||
| 80 | | Q / E | left / right shoulder | | ||
| 81 | | Esc | `Menu` | | ||
| 82 | | Tab | `View` | | ||
| 83 | |||
| 84 | This is enough to drive menus and press prompts. The sticks and triggers stay at rest: moving with WASD and aiming | ||
| 85 | with the mouse are for a later change. Letters are Windows virtual-key codes, so `Y` is the key labelled Y on the | ||
| 86 | active layout (it sits where Z does on a QWERTY keyboard with a German layout). | ||
| 87 | |||
| 88 | Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video | ||
| 89 | subsystem, which this build leaves out) and works under Wine. With `LEONIDA_KEYBOARD_PAD=1` keys count only while a | ||
| 90 | window of this process is in the foreground, so typing in another application presses nothing, and every button is | ||
| 91 | released when focus moves away. `LEONIDA_KEYBOARD_PAD=always` reads them whatever has focus; a console tool such as | ||
| 92 | `gameinput_probe` needs it, because its console window belongs to the terminal, not to the tool. | ||
| 93 | |||
| 94 | To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. | ||
| 95 | |||
| 65 | ## Rumble and triggers | 96 | ## Rumble and triggers |
| 66 | 97 | ||
| 67 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on | 98 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on |
| @@ -101,6 +132,7 @@ An effect is sent only when its bytes change, so a steady level costs one report | |||
| 101 | | `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour | | 132 | | `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour | |
| 102 | | `LEONIDA_RUMBLE` | `1` | `0` turns all rumble and trigger output off | | 133 | | `LEONIDA_RUMBLE` | `1` | `0` turns all rumble and trigger output off | |
| 103 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 134 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 135 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | | ||
| 104 | 136 | ||
| 105 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 137 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to |
| 106 | leave a DualSense to the generic driver, or `SDL_GAMECONTROLLERCONFIG` to add a mapping for an unknown pad. | 138 | leave a DualSense to the generic driver, or `SDL_GAMECONTROLLERCONFIG` to add a mapping for an unknown pad. |
| @@ -143,7 +175,9 @@ shim fills (`GameInputDeviceInfo` 320 bytes with `deviceFamily` at 96 and the in | |||
| 143 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, | 175 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, |
| 144 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the guide button, motor and trigger | 176 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the guide button, motor and trigger |
| 145 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a | 177 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a |
| 146 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. | 178 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. The keyboard pad is |
| 179 | driven through `rt::gameinput::set_keyboard_source` with fake keys and focus: every binding, two keys at once, no | ||
| 180 | input out of focus, release on focus loss, the `always` mode, and turning it off and on again. | ||
| 147 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and | 181 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and |
| 148 | trigger for a second with `--rumble`, then prints the live reading. | 182 | trigger for a second with `--rumble`, then prints the live reading. |
| 149 | 183 | ||
| @@ -164,5 +198,8 @@ These need the game executable or a test on hardware: | |||
| 164 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. | 198 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. |
| 165 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only | 199 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only |
| 166 | that. | 200 | that. |
| 201 | - **Keyboard pad as a second pad**: it is one more connected gamepad, so with a controller plugged in the title sees | ||
| 202 | two. A title that follows only the first pad it saw, or asks the player to press a button to pick the active pad, | ||
| 203 | may ignore one of them; whether the game does either is unknown. | ||
| 167 | - **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's | 204 | - **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's |
| 168 | `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad. | 205 | `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad. |