Mapping DevTerm R-01 Gamepad to Keys in Xorg

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,

  1. Map D-Pad to up/down/left/right
  2. Map YBXA to hjkl
  3. 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
  1. Using Gamepad arrows and buttons in command line apps - #16 by Paul_McGuinness
  2. https://www.x.org/releases/current/doc/man/man4/joystick.4.xhtml
2 Likes