Host input for the virtual pad: XInput controllers, keyboard mapping, rumble (was #47) #207

Closed
QuentinDanblon wants to merge 1 commit from upstream-pr/207 into main
QuentinDanblon commented 2026-11-23 01:16:34 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-23T01:16:34Z.


Library / area: compat-common (GameInput virtual pad)

Exports changed (exports.txt rows): none

Source of the behaviour: XInput and GameInput public documentation (Microsoft Learn). No third-party code.

Part of the split of #152 (was #47): the pad host / gamepad change on its own. Based on c2a3522, 5 files, +654 / -8, only compat-common.

  • pad_host.rs feeds the virtual gamepad from a real XInput pad (xinput1_4.dll, loaded at run time), only while the host GameInput reports no gamepad itself.
  • A keyboard-to-pad mapping is sampled while a window of the title is in the foreground. It turns off once the title asks GameInput for keyboard readings.
  • Scripted pad commands win while a command file runs or a scripted down is held.
  • SetRumbleState on the virtual pad sends the low and high motors to the XInput pad that feeds it.
  • Host changes are pushed to the reading history of the virtual pad, so GetNextReading / GetPreviousReading see them like scripted ones.
  • Config: TOMBOX_PAD_XINPUT / pad_xinput, TOMBOX_PAD_KEYS / pad_keys.

tools/dev/pad.ps1 is not touched. The one change #47 made to it, for when you regenerate it, was a line in the help output: host input (a real XInput pad, keyboard WASD/arrows/Space... while the title window is focused) feeds the same pad; a running script, or a scripted 'down' not yet released, masks it (compat-common pad_host.rs).

Tests: eight unit tests in pad_host.rs (XInput buttons and axes to GameInput values, key mapping, combining sources, scripted pad priority, modes and window classes, rumble levels), tests/pad_host.rs (a key pressed in a foreground window reaches the published reading) and host_state_reaches_readings_and_their_history in gamepad.rs.

Results

--release, this branch alone on c2a3522 (it merges into 2eda8b0 without conflict, not rerun there):

  • cargo test -p compat-common --lib -- pad_host gamepad host_input gameinput: 33 passed, 0 failed.
  • --test gameinput_ext: 3 passed.
  • --test pad_host: 1 passed, but on this run it skipped its key injection: the test process could not take the foreground (foreground lock), and the test then returns early by design. So the path from a real key press to the published reading was not exercised here.

No comment lines added (PR gate: 5 files checked, 0 problems). Not run against a title, and not run with a physical pad on this base.

  • cargo test -p compat-common passes for the pad, GameInput and host input tests
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6550283584 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/207). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-23T01:16:34Z. --- **Library / area:** compat-common (GameInput virtual pad) **Exports changed (exports.txt rows):** none **Source of the behaviour:** XInput and GameInput public documentation (Microsoft Learn). No third-party code. Part of the split of #152 (was #47): the pad host / gamepad change on its own. Based on `c2a3522`, 5 files, +654 / -8, only `compat-common`. - `pad_host.rs` feeds the virtual gamepad from a real XInput pad (`xinput1_4.dll`, loaded at run time), only while the host GameInput reports no gamepad itself. - A keyboard-to-pad mapping is sampled while a window of the title is in the foreground. It turns off once the title asks GameInput for keyboard readings. - Scripted pad commands win while a command file runs or a scripted `down` is held. - `SetRumbleState` on the virtual pad sends the low and high motors to the XInput pad that feeds it. - Host changes are pushed to the reading history of the virtual pad, so `GetNextReading` / `GetPreviousReading` see them like scripted ones. - Config: `TOMBOX_PAD_XINPUT` / `pad_xinput`, `TOMBOX_PAD_KEYS` / `pad_keys`. `tools/dev/pad.ps1` is not touched. The one change #47 made to it, for when you regenerate it, was a line in the help output: `host input (a real XInput pad, keyboard WASD/arrows/Space... while the title window is focused) feeds the same pad; a running script, or a scripted 'down' not yet released, masks it (compat-common pad_host.rs)`. Tests: eight unit tests in `pad_host.rs` (XInput buttons and axes to GameInput values, key mapping, combining sources, scripted pad priority, modes and window classes, rumble levels), `tests/pad_host.rs` (a key pressed in a foreground window reaches the published reading) and `host_state_reaches_readings_and_their_history` in `gamepad.rs`. ### Results `--release`, this branch alone on `c2a3522` (it merges into `2eda8b0` without conflict, not rerun there): - `cargo test -p compat-common --lib -- pad_host gamepad host_input gameinput`: 33 passed, 0 failed. - `--test gameinput_ext`: 3 passed. - `--test pad_host`: 1 passed, but on this run it skipped its key injection: the test process could not take the foreground (foreground lock), and the test then returns early by design. So the path from a real key press to the published reading was not exercised here. No comment lines added (PR gate: 5 files checked, 0 problems). Not run against a title, and not run with a physical pad on this base. - [x] `cargo test -p compat-common` passes for the pad, GameInput and host input tests - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
omonkeyz commented 2026-11-23 01:57:39 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T01:57:39Z.


Applied in 0f84770 (merged in ad24144) with your authorship kept, thanks. One change on top, in 563322a: host input is now opt-in. Our automated runs show visible title windows, and must never take real pad or keyboard input. So TOMBOX_PAD_XINPUT and TOMBOX_PAD_KEYS (and the pad_xinput / pad_keys cfg entries) now default to off. Setting 1 forces a source on, and auto gives your original behaviour. The unit test and tests/pad_host.rs were updated to match. The trailing comments in the key table were dropped in f9c3ec5.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7089548882 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/207#issuecomment-7089548882). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T01:57:39Z. --- Applied in 0f84770 (merged in ad24144) with your authorship kept, thanks. One change on top, in 563322a: host input is now opt-in. Our automated runs show visible title windows, and must never take real pad or keyboard input. So TOMBOX_PAD_XINPUT and TOMBOX_PAD_KEYS (and the pad_xinput / pad_keys cfg entries) now default to off. Setting 1 forces a source on, and auto gives your original behaviour. The unit test and tests/pad_host.rs were updated to match. The trailing comments in the key table were dropped in f9c3ec5.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!207
No description provided.