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

Closed
github-bot wants to merge 1 commit from gh-pr/207/head into gh-pr/207/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 01:16 UTC · original
QuentinDanblon:pr/pad-host → main · +654 −8 · 5 files · 1 commits · closed without merging

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

**@⁠QuentinDanblon** on GitHub · 2026-11-23 01:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/207) `QuentinDanblon:pr/pad-host` → `main` · +654 −8 · 5 files · 1 commits · closed without merging **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)
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)
and from a keyboard-to-pad mapping sampled while a window of the title is in
the foreground (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 low/high motors to the feeding
XInput pad. Config: TOMBOX_PAD_XINPUT / pad_xinput, TOMBOX_PAD_KEYS / pad_keys.
Host changes are pushed to the virtual pad's reading history, so
GetNextReading / GetPreviousReading see them like scripted ones.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:13:55 +00:00
github-bot closed this pull request 2026-11-26 06:13:55 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 01:57 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-23 01:57 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/207#issuecomment-7089548882) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.