# Mapping DevTerm R-01 Gamepad to Keys in Xorg

**URL:** <https://forum.clockworkpi.com/t/mapping-devterm-r-01-gamepad-to-keys-in-xorg/9596>\
**Category:** DevTerm\
**Tags:** tinkering\
**Created:** [February 7, 2023, 11:57pm UTC](https://forum.clockworkpi.com/t/mapping-devterm-r-01-gamepad-to-keys-in-xorg/9596 "2023-02-07T23:57:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecliptik](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/ecliptik/32/6959_2.png) [@ecliptik](https://forum.clockworkpi.com/u/ecliptik)\
**Post date:** [February 7, 2023, 11:57pm UTC](https://forum.clockworkpi.com/t/mapping-devterm-r-01-gamepad-to-keys-in-xorg/9596/1 "2023-02-07T23:57:37Z")

</div>

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.

```auto
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](https://forum.clockworkpi.com/t/using-gamepad-arrows-and-buttons-in-command-line-apps/7059/16)
2. [https://www.x.org/releases/current/doc/man/man4/joystick.4.xhtml](https://www.x.org/releases/current/doc/man/man4/joystick.4.xhtml)
