1. PrequisitesFirst 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 filesXBMC 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 <global> and then you start a joystick entry:
Then follows the button/axis configuration. For a button add an entry:
for an axis add:
<axis id="AXIS_ID" limit="VALUE_LIMIT">NAME_OF_XBMC_ACTION</axis>
and for a D-PAD or hat add:
<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:
<axis id="1" limit="-1">AnalogSeekBack</axis>
<hat id="1" direction="left">Left</hat>
Finish the file with closing all sections again:
Save the file (here's my keymap file as reference) and start XBMC. You gamepad should work now. Enjoy.