Linux mouse-to-joystick injector for RetroArch that grabs your mouse via evdev and maps it to a virtual gamepad stick via uinput. Works with any game on any core, on Wayland or X11.
- Rust
- Linux evdev / uinput
- Unix signals (SIGUSR1)
- clap CLI framework
m2joy reads raw mouse input from /dev/input/eventX, creates a virtual gamepad ("m2joy Stick") via /dev/uinput, and converts mouse velocity to analog stick deflection at 1kHz using an exponential moving average.
Control is fully command-based. Run m2joy toggle from another process to grab or ungrab the mouse—designed for Hyprland, sway, or any window manager keybind. Under the hood, toggle sends a SIGUSR1 signal to the running instance. No keyboard device access required.
Mouse buttons are forwarded as gamepad triggers: left click maps to R2 (shoot) and right click maps to L2 (aim). RetroArch autoconfig is installed on first run so the virtual gamepad is recognized automatically.
- 1kHz polling loop with EMA smoothing for stable analog stick output
- Mouse buttons forwarded as gamepad triggers (left click → R2, right click → L2)
- Virtual gamepad via uinput with automatic RetroArch autoconfig installation
- Command-based toggle with
m2joy toggleandm2joy quit - SIGUSR1 signal toggle for window manager keybind integration
- Auto-detection of mouse device from
/dev/input/event* - Configurable sensitivity, Y-axis inversion, and stick output
- Left or right stick output selection
- Evdev grab/ungrab to capture and release the mouse
- Add per-game config profiles
- Build acceleration curves for non-linear sensitivity
- Add support for multiple mice
- Create a status indicator via desktop notification
- Add yourself to the input group with
sudo usermod -aG input $USERand re-login - Ensure uinput is loaded with
sudo modprobe uinput - Build with
cargo build --release - Run
./target/release/m2joyto start the daemon - Toggle grab with
m2joy togglefrom another terminal or keybind - In RetroArch go to Settings > Input > Port 1 Controls > Device Index and select m2joy Stick
bind = SUPER, F9, exec, m2joy toggle
bindsym $mod+F9 exec m2joy toggle
| Option | Default | Description |
|---|---|---|
-s, --sensitivity |
1.0 | Mouse sensitivity multiplier |
--invert-y |
off | Invert Y axis |
-d, --device |
auto | Specific evdev path (e.g. /dev/input/event5) |
--left-stick |
off | Output to left stick instead of right |
--debug |
off | Print diagnostics every 100ms |
MIT