Using an USB joystick or gamepad in XBMC on Ubuntu

Now I have those cheap USB gamepads, XBMC running, the ROM collection browser addon and MAME all set up. Awesome! But why can’t I navigate XBMC with my joystick to select games and adjust the volume etc?! Here’s how to solve that problem…


1. Prequisites

First of all you need joystick support and some tools. Go ahead and install the joystick package in Ubuntu with “sudo apt-get install joystick”. That gives you joystick tools like jstest and jscal which we’ll need later.
Run “cat /proc/bus/input/devices” which shows you a list of all input devices your system has. Locate the entry describing your joystick and write down or copy the exact string after “NAME=…”, including all spaces etc.! We’ll need that later. The last string of the line “Handlers=…” should read jsX with X corresponding to the number of the joystick.
Now start the tool jstest with the joystick you want to use, like so: “jstest /dev/input/js0”. It will show you the states of all of the buttons and axes of js0 and you can see them change when you use the joystick. Find out which indexes correspond to which axis or button.

2. XBMC keymap files

XBMC uses keymap xml files to connect input device “keys” to XBMC functions. We need to create a keymap file for our joystick. Create a new keymap file in your users keymap folder using an editor of you choice and name it after your joysticks name, e.g. “nano ~/.xbmc/userdata/keymaps/joystick.SOMENAME.xml”.
The file starts with <keymap>, then <gloabal> and then you start a joystick entry:

<keymap>
   <global>
      <joystick name="NAME_OF_YOUR_JOYSTICK">

Then follows the button/axis configuration. For a button, axis or D-PAD / hat add:

<button id="BUTTON_ID">NAME_OF_XBMC_ACTION</button>
<axis id="AXIS_ID" limit="VALUE_LIMIT">NAME_OF_XBMC_ACTION</axis>
<had id="HAT_ID" position="DIRECTION">"NAME_OF_XBMC_ACTION</hat>

BUTTON_ID, AXIS_ID and HAT_ID correspond to the index you got from jstest above +1, as jstests indices start as 0, but XBMC seems to start from 1…
VALUE_LIMIT is the limit that needs to be reached so XBMC activates that function. The default value of an axis is usually 0, so use “+1” and “-1” for the different directions of the axis.
DIRECTION is the direction of the D-PAD or hat and takes strings like “left”, “right”, “up” or “down”.
NAME_OF_XBMC_ACTION is the function that should be executed in XBMC. A list of possible actions can be found here. An example for that section could be:

<button id="3">Select</button>
<axis id="1" limit="-1">AnalogSeekBack</axis>
<hat id="1" direction="left">Left</hat>

 Finish the file with closing all sections again:

        </joystick>
    </global>
</keymap>

Save the file (here’s my keymap file as reference) and start XBMC. You gamepad should work now. Enjoy.

Published by HorstBaerbel

Software developer by trade and interest, but I venture into the electronics- and diy-world from time to time.

9 thoughts on “Using an USB joystick or gamepad in XBMC on Ubuntu

  1. Seems that XBMC for RPi are compiled without joystick enable so I will need to try another solution such joy2key but I'm not getting it work to.You have XBMC with joystick working on RPi?

    Like

  2. Na, sorry. I'm using XBMC a PC… Some poeple seem to be compiling it themselves with with joystick support. Maybe you could try that.

    Like

Leave a comment

Design a site like this with WordPress.com
Get started