Skip to content

Smooth mouse-to-stick aiming: speed mode, stick mixing and raw mouse input - #146

Open
luttje wants to merge 11 commits into
mainfrom
fix/mouse-to-stick-rate-control
Open

luttje wants to merge 11 commits into
mainfrom
fix/mouse-to-stick-rate-control

Conversation

@luttje

@luttje luttje commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Heya! This makes mouse aiming via a virtual stick work properly for games where the stick controls turn speed rather than aim position. It was prompted by @domi811 trying to play WAR: Final Assault in MAME with mouse aim (discussion): horizontal aiming only turned in fixed steps, and sometimes flicked the wrong way.

What was wrong

  • Exact stick values were all-or-nothing. Any non-zero value (e.g. 100, or even 1) gave full deflection, so mouse movement became "full speed for 25 ms" pulses.
  • Stick inputs fought each other. Mappings added onto the stick and clamped at every step, so holding two keys and releasing one could leave the stick stuck. A reset from one mapping also wiped out what other mappings were doing on the same stick.
  • Mouse movement drifted. Movement was measured against the last cursor position seen, so anything that moved the cursor (a game, alt-tab) skewed all movement in one direction.

What changed

  • Exact stick values are now fractions (-1 to 1), in the editor and in GamePad.SimulateMove. Existing profiles keep working: ±1 is still full deflection, and larger values are clamped to it.
  • New GamePadStickMixer combines all mappings on a stick and only clamps the final value, so a press and its release always cancel out.
  • New "Speed" input mode for stick actions: the stick follows how fast the mouse moves and returns to center when it stops. It has settings for full-speed point, smoothing, curve and minimum output. Accumulate (the old behavior) stays the default.
  • Mouse movement is measured from the real cursor position, which fixes the drift.
  • Opt-in "Use Raw Mouse Movement" setting. Reads the mouse through Raw Input, without Windows pointer acceleration. Off by default, because input scales and speeds would need retuning.

Editor fixes found along the way:

  • "Reset After" now shows in input mode too.
  • "Reset After" is disabled when Hold is ticked.
  • Ticking Hold on an existing mapping now actually saves the reverse mapping.
  • Unticking Hold removes the reverse mapping, after a confirmation.

Compatibility

No profile migration needed. Old profiles load and behave the same, minus the drift and stuck-stick bugs. All new options are opt-in.

Testing

This is some of the testing I did that's noteworthy:

  • Manually tested in MAME (warfab) with a mouse-aim profile: X in Speed mode, Y in Accumulate mode:
    1. I started and armed Key2Joy
    2. Started War Final Assault with mame warfab -joystick -nomouse -joystick_deadzone 0 -joystick_saturation 1
    3. I tried to calibrate the joystick. Something went wrong here for me and I'm not familiar enough with MAME, this game or arcade joystick calibration to fix it ending up with a continuous drift left or right. This sounds like a me-problem, more than a MAME or Key2Joy problem, so I'll leave it to @domi811 to test correctly for their use-case.
    4. It worked fine, feeling somewhat like Quake movement, except for the drift I caused in the previous step.
  • Quick check: mapped Mouse Move (Any) → stick in Speed mode, armed it, and used a joystick tester. Slow movement should give small deflection, fast movement large deflection, and the stick should center when you stop.

Related issues

…ction from -1 to 1, so 0.5 means half. Before, any non-zero value pushed the stick all the way
In speed mode, the stick follows how fast relative input (like the mouse) moves and returns to the center when it stops. This suits games where the stick sets how fast you turn, instead of where you aim. Accumulate mode (the existing behavior) stays the default, so profiles are unchanged.
…eTriggerCenter is no longer needed and is kept as a no-op.
@luttje luttje self-assigned this Nov 25, 2026
@luttje luttje added the enhancement New feature or request label Nov 25, 2026
@luttje
luttje requested a balanced review from Copilot November 25, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cancelling the mapping dialog leaves profile edits in place, allowing mismatched press and reverse actions to be persisted on a later save.

5 open issues
What changed in this PR

This PR improves mouse-to-stick aiming for games where stick deflection controls turn speed, adding configurable speed tracking and shared stick mixing.

Changes:

  • Adds Speed mode, fractional exact values, and stick contribution mixing.
  • Adds opt-in raw mouse input and revises cursor-based movement measurement.
  • Updates Hold/reverse-mapping editing, reset controls, API documentation, and unit tests.
File Description
Support/​Key2Joy.Tests/​Core/​Mapping/​Actions/​Input/​StickSpeedTrackerTests.cs Tests speed calculation, decay, and output curves.
Support/​Key2Joy.Tests/​Core/​Mapping/​Actions/​Input/​GamePadStickMixerTests.cs Tests contribution mixing, clamping, and resets.
Key2Joy.App/​UserControls/​MappingControl.xaml.cs Adds confirmation for reverse-mapping removal.
Key2Joy.App/​UserControls/​Actions/​Input/​GamePadStickActionControl.xaml.cs Connects speed settings and Hold-aware reset options.
Key2Joy.App/​UserControls/​Actions/​Input/​GamePadStickActionControl.xaml Adds speed controls and fractional exact-value inputs.
Key2Joy.App/​UserControls/​Actions/​ActionControl.xaml.cs Propagates reverse-mapping state to action options.
Key2Joy.App/​Pages/​MainMappingPageViewModel.cs Ensures newly created child mappings enter the profile.
Key2Joy.App/​Pages/​MainMappingPage.xaml.cs Handles confirmed child-mapping removal.
Docs/​Api/​Input/​GamePad.SimulateMove.md Documents fractional parameters and corrects axis directions.
Core/​Key2Joy.Core/​Mapping/​Triggers/​Mouse/​MouseMoveTriggerListener.cs Revises movement measurement and integrates raw input.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​StickSpeedTracker.cs Calculates windowed speed and stick output.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​StickSpeedTicker.cs Schedules background speed updates.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​GamePadStickMixer.cs Combines stick contributions and applies clamped output.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​GamePadStickInputMode.cs Defines Accumulate and Speed modes.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​GamePadStickAxis.cs Defines stick-axis identifiers.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​GamePadStickAction.cs Implements fractional movement, mixing, and speed mode.
Core/​Key2Joy.Core/​Mapping/​Actions/​Input/​GamePadResetAction.cs Routes resets through gamepad state reset.
Core/​Key2Joy.Core/​LowLevelInput/​SimulatedGamePad/​SimulatedGamePad.cs Clears mixer contributions during reset.
Core/​Key2Joy.Core/​LowLevelInput/​RawMouseInput.cs Adds a Windows Raw Input mouse reader.
Core/​Key2Joy.Core/​Config/​ConfigState.cs Adds the opt-in raw mouse setting.
Core/​Key2Joy.Contracts/​Mapping/​Actions/​IReverseMappingAwareOptionsControl.cs Defines reverse-mapping awareness for option controls.

Review effort: Balanced

…cumulation

- Validate mapping edits on a draft and only apply them after the "remove child mappings" confirmation, so cancelling leaves the profile untouched.
- Publish speed mode values while holding the speed lock, so a tick can't leave a stale value behind after disarm.
- Store accumulated relative input per trigger listener instead of per action, so separate directional mappings (e.g. Mouse Move Left and Right) can fully undo each other again, like before the stick mixer.
@luttje
luttje requested a review from abart27 November 25, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

2 participants