Real controller (XInput) and keyboard input for the virtual pad, rumble to the host pad #47

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

@⁠QuentinDanblon on GitHub · 2026-11-21 19:36 UTC · original
QuentinDanblon:feat/host-input → main · +680 −7 · 6 files · 104 commits · closed without merging

Library / area: compat-common (virtual pad, GameInput wrapper): real controller and keyboard input

Exports changed (exports.txt rows): none

Source of the behaviour: Windows SDK Xinput.h / learn.microsoft.com XInput docs (XINPUT_GAMEPAD layout, ranges, XINPUT_VIBRATION), GDK GameInputGamepadState ranges, the existing BTN_*/rumble layout in this crate

Problem

BLOCKERS lists "Keyboard input: not started", and the README milestone "Keyboard / controller input" is not reached. The virtual pad in gamepad.rs is fed only by pad.ps1 scripts. A real XInput controller that host GameInput doesn't serve never reached the title. A pad-only title couldn't be played from the keyboard. The virtual pad's SetRumbleState was dropped (ret_zero slots, gamepad.rs:302-304).

A local probe found that the host GameInput already gives the title the real keyboard and mouse (GetCurrentReading S_OK for kinds 0x10/0x30), so I didn't add an emulated keyboard device.

Change

New pad_host.rs, feeding the existing virtual pad:

  • XInput: xinput1_4.dll loaded dynamically, 4 ms poll on the first connected user (slots rescanned once per second when none is connected).
    • Buttons map to the GameInput bits. Triggers are value/255. Sticks map to [-1, 1] with Y up, like the virtual pad. No dead zone: XInput docs say that is the application's job.
    • Doubling guard: the feed runs only while host GameInput itself returns no gamepad reading (rechecked every 2 s), so a pad isn't exposed twice.
  • Keyboard → pad, read only while one of the title's own windows has focus (not TomBoxGdkDialog/TomBoxFrontPanel):
    • WASD left stick, arrows right stick (diagonals on the unit circle, opposite keys cancel).
    • Space A, Backspace B, E X, R Y, Q LB, F RB, Z/RMB LT, X/LMB RT, LShift LS, C RS, IJKL d-pad, Esc Menu, Tab View.
    • Turns itself off once the title reads GameInput keyboard readings, so a key doesn't count twice.
  • Script wins: while a pad.ps1 batch runs, or its state isn't neutral, the scripted state is published unchanged. Otherwise host input is published. Host sources are merged (buttons OR-ed, each stick or trigger taken from the source that moves it further).
  • Rumble: the virtual pad's device vtable uses the existing install_pad_feedback. SetRumbleState low/high frequency goes to XInputSetState when a real pad is the source. Trigger motors are stored only (no XInput equivalent). supportedRumbleMotors now reports 0x3.
  • Config, following the existing env-then-tombox.cfg convention: TOMBOX_PAD_XINPUT/pad_xinput and TOMBOX_PAD_KEYS/pad_keys. 0 disables, force ignores the auto guards. TOMBOX_PAD=0 still turns the whole virtual pad off.

Tests

  • cargo test -p compat-common --lib -- pad_host gamepad: 14 pass, 8 of them new. They cover button bits, axis edges (−32768/32767/0, triggers 0/128/255), no dead zone, the key map (cancelling, diagonals), source combine, the script-wins merge, config parsing, window classes, and motor speed clamping/NaN.
  • --test pad_host (new): creates a window, makes it foreground, injects W via SendInput, checks left-stick Y = 1.0 and neutral after release. It skips when the process can't take the foreground (cargo here did skip). A manual run that took the foreground passed.
  • --test gameinput_ext: 14 pass, including rumble/FF with the forwarding.
  • Other compat-common binaries fail only where they need local data that isn't in git (backend_data, analysis/gdk, query_accum.dxil). This branch doesn't change them.

Not verified

No physical controller on this machine (XInput returns 1167 on all slots). The XInput feed and rumble are covered only by the pure mapping tests. Not run in a title with a person playing: the next step is to focus a pad-only title and check the [gamepad] host -> … lines. A title that reads WM_KEYDOWN instead of GameInput would get both the keys and the mapped pad (pad_keys=0 turns the mapping off). Mouse movement isn't mapped to the right stick, because that needs raw input and cursor capture. Clicking to focus the window also presses RT for that frame. The virtual pad still has no reading history and no RegisterReadingCallback.

  • cargo test -p compat-common passes (except the local-data tests above)
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
**@⁠QuentinDanblon** on GitHub · 2026-11-21 19:36 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/47) `QuentinDanblon:feat/host-input` → `main` · +680 −7 · 6 files · 104 commits · closed without merging **Library / area:** compat-common (virtual pad, GameInput wrapper): real controller and keyboard input **Exports changed (exports.txt rows):** none **Source of the behaviour:** Windows SDK `Xinput.h` / learn.microsoft.com XInput docs (XINPUT_GAMEPAD layout, ranges, XINPUT_VIBRATION), GDK `GameInputGamepadState` ranges, the existing BTN_*/rumble layout in this crate ### Problem BLOCKERS lists "Keyboard input: not started", and the README milestone "Keyboard / controller input" is not reached. The virtual pad in `gamepad.rs` is fed only by `pad.ps1` scripts. A real XInput controller that host GameInput doesn't serve never reached the title. A pad-only title couldn't be played from the keyboard. The virtual pad's `SetRumbleState` was dropped (`ret_zero` slots, gamepad.rs:302-304). A local probe found that the host GameInput already gives the title the real keyboard and mouse (GetCurrentReading S_OK for kinds 0x10/0x30), so I didn't add an emulated keyboard device. ### Change New `pad_host.rs`, feeding the existing virtual pad: - **XInput**: `xinput1_4.dll` loaded dynamically, 4 ms poll on the first connected user (slots rescanned once per second when none is connected). - Buttons map to the GameInput bits. Triggers are value/255. Sticks map to [-1, 1] with Y up, like the virtual pad. No dead zone: XInput docs say that is the application's job. - Doubling guard: the feed runs only while host GameInput itself returns no gamepad reading (rechecked every 2 s), so a pad isn't exposed twice. - **Keyboard → pad**, read only while one of the title's own windows has focus (not TomBoxGdkDialog/TomBoxFrontPanel): - WASD left stick, arrows right stick (diagonals on the unit circle, opposite keys cancel). - Space A, Backspace B, E X, R Y, Q LB, F RB, Z/RMB LT, X/LMB RT, LShift LS, C RS, IJKL d-pad, Esc Menu, Tab View. - Turns itself off once the title reads GameInput keyboard readings, so a key doesn't count twice. - **Script wins**: while a `pad.ps1` batch runs, or its state isn't neutral, the scripted state is published unchanged. Otherwise host input is published. Host sources are merged (buttons OR-ed, each stick or trigger taken from the source that moves it further). - **Rumble**: the virtual pad's device vtable uses the existing `install_pad_feedback`. `SetRumbleState` low/high frequency goes to `XInputSetState` when a real pad is the source. Trigger motors are stored only (no XInput equivalent). `supportedRumbleMotors` now reports 0x3. - **Config**, following the existing env-then-`tombox.cfg` convention: `TOMBOX_PAD_XINPUT`/`pad_xinput` and `TOMBOX_PAD_KEYS`/`pad_keys`. `0` disables, `force` ignores the auto guards. `TOMBOX_PAD=0` still turns the whole virtual pad off. ### Tests - `cargo test -p compat-common --lib -- pad_host gamepad`: 14 pass, 8 of them new. They cover button bits, axis edges (−32768/32767/0, triggers 0/128/255), no dead zone, the key map (cancelling, diagonals), source combine, the script-wins merge, config parsing, window classes, and motor speed clamping/NaN. - `--test pad_host` (new): creates a window, makes it foreground, injects W via `SendInput`, checks left-stick Y = 1.0 and neutral after release. It skips when the process can't take the foreground (cargo here did skip). A manual run that took the foreground passed. - `--test gameinput_ext`: 14 pass, including rumble/FF with the forwarding. - Other compat-common binaries fail only where they need local data that isn't in git (`backend_data`, `analysis/gdk`, `query_accum.dxil`). This branch doesn't change them. ### Not verified No physical controller on this machine (XInput returns 1167 on all slots). The XInput feed and rumble are covered only by the pure mapping tests. Not run in a title with a person playing: the next step is to focus a pad-only title and check the `[gamepad] host -> …` lines. A title that reads `WM_KEYDOWN` instead of GameInput would get both the keys and the mapped pad (`pad_keys=0` turns the mapping off). Mouse movement isn't mapped to the right stick, because that needs raw input and cursor capture. Clicking to focus the window also presses RT for that frame. The virtual pad still has no reading history and no RegisterReadingCallback. - [x] `cargo test -p compat-common` passes (except the local-data tests above) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
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.

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

@⁠QuentinDanblon on GitHub · 2026-11-21 22:02 UTC · original

Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 22:02 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7069900464) Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 11:36 UTC · original

Rebased onto 51f5319. Main now passes the host GameInput devices through to the title (gamepad/host.rs, host_input.rs), so what this PR still adds is:

  • keyboard to pad mapping, for a title that reads only the gamepad (BLOCKERS 355 still lists keyboard input as not started);
  • an XInput pad that host GameInput does not report. As before, the feed stays paused while GameInput reports a gamepad itself;
  • SetRumbleState on the virtual pad, forwarded to the XInput pad feeding it.

Adapted to main's hide settings: with TOMBOX_HOST_PAD=0 the XInput feed is off, and with TOMBOX_HOST_KBM=0 the key mapping is off, both until a takeover (host_input::pad_hidden() / kbm_hidden()). A test run still sees only the scripted pad.

Tests on this base:

  • cargo test -p compat-common --release --lib -- pad_host gamepad host_input: 28 pass.
  • --test gameinput_ext: 14 pass.
  • --test pad_host: 1 pass (it skips when the process cannot take the foreground).
  • Not run against a title.
**@⁠QuentinDanblon** on GitHub · 2026-11-22 11:36 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7078556195) Rebased onto `51f5319`. Main now passes the host GameInput devices through to the title (`gamepad/host.rs`, `host_input.rs`), so what this PR still adds is: - keyboard to pad mapping, for a title that reads only the gamepad (BLOCKERS 355 still lists keyboard input as not started); - an XInput pad that host GameInput does not report. As before, the feed stays paused while GameInput reports a gamepad itself; - `SetRumbleState` on the virtual pad, forwarded to the XInput pad feeding it. Adapted to main's hide settings: with `TOMBOX_HOST_PAD=0` the XInput feed is off, and with `TOMBOX_HOST_KBM=0` the key mapping is off, both until a takeover (`host_input::pad_hidden()` / `kbm_hidden()`). A test run still sees only the scripted pad. Tests on this base: - `cargo test -p compat-common --release --lib -- pad_host gamepad host_input`: 28 pass. - `--test gameinput_ext`: 14 pass. - `--test pad_host`: 1 pass (it skips when the process cannot take the foreground). - Not run against a title.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please rebase on the current gamepad.rs and strip comment lines. Note that tools/dev/pad.ps1 is regenerated on our side, so describe that change in the PR text. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7079648394) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please rebase on the current gamepad.rs and strip comment lines. Note that tools/dev/pad.ps1 is regenerated on our side, so describe that change in the PR text. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

Pull request closed

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