Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Disable gamepad input as mouse input

I added an answer to AskUbuntu, based on a different answer. Here is a small function that easily enables/disables using the features provided by package xserver-xorg-input-joystick.

jsinput() {
    # Insert your controller name here, as seen from `xinput --list`.
    _c="$( xinput --list --id-only 'Logic3 Controller' )"
    # Default is off, unless you pass "yes" or similar as first parameter.
    _mode="0" ; echo "${1}" | grep -qiE '\<(yes|1|y|on)\>' && _mode=1
    # Find ids of these property names, and then tell each one to go to the mode chosen in the previous line.
    xinput list-props "${_c}" | sed -n -r -e '/Generate (Mouse|Key)/{s/.*\(([0-9]+)\).*/\1/;p}' | xargs -I@ xinput set-prop "${_c}" @ "${_mode}"
}

If you stick this in your ~/.bashrc you could then run jsinput to disable this controller as mouse input. To turn on mouse input you could then simply run jsinput 1 or jsinput on.

Comments