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

Closed
QuentinDanblon wants to merge 0 commits from upstream-pr/47 into main
QuentinDanblon commented 2026-11-21 19:36:25 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T19:36:25Z.


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
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6533479865 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/47). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T19:36:25Z. --- **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
QuentinDanblon commented 2026-11-21 22:02:47 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T22:02:47Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7069900464 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7069900464). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T22:02:47Z. --- 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 commented 2026-11-22 11:36:47 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-22T11:36:47Z.


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.
<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7078556195 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7078556195). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-22T11:36:47Z. --- 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.
omonkeyz commented 2026-11-22 13:12:52 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:52Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079648394 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/47#issuecomment-7079648394). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:12:52Z. --- 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

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!47
No description provided.