I wanted to use the gamepad on my DevTerm R-01 as arrow keys and HJKL for vi-like navigation. When searching the forum, I found the thread on flipping DIP switch #2 to on [1], but this didn’t work on my R-01 for some reason.
I tried out some other methods like xmodmap
, triggerhappy
, etc, but finally had the idea to use the Xorg joystick driver to emulate key presses.
After reading some documentation on joysticks in Xorg [2], I came up with this Xorg configuration that will,
- Map D-Pad to up/down/left/right
- Map YBXA to hjkl
- Disable the joystick as a mouse
To set this up, install the xserver-xorg-input-joystick
package on Ubuntu, put the following configuration in /etc/X11/xorg.conf.d/51-joystick.conf
, and restart Xorg.
Section "InputClass"
Identifier "DevTerm Gamepad"
Option "StartKeysEnabled" "True"
Option "MatchDevicePath" "/dev/input/event*"
Option "MatchIsJoystick" "on"
#Do not use as a mouse
Option "StartMouseEnabled" "False"
#XABY buttons
#Keycodes: 43=h, 44=j, 45=k, 46=l
Option "MapButton1" "key=45" #X
Option "MapButton2" "key=46" #A
Option "MapButton3" "key=44" #B
Option "MapButton4" "key=43" #Y
#D-Pad
#Keycodes: 111=up, 116=down, 113=left, 114=right
Option "MapAxis1" "mode=accelerated keylow=113 keyhigh=114" #left/right
Option "MapAxis2" "mode=accelerated keylow=111 keyhigh=116" #up/down
Option "MapAxis3" "mode=accelerated keylow=113 keyhigh=114" #left/right
Option "MapAxis4" "mode=accelerated keylow=111 keyhigh=116" #up/down
EndSection