emblemparade.com

Faking an Xbox 360 Controller in Linux

So many great Linux games, so little time...

And many of them “just work” with gamepads, due to the excellent driver support in Linux. And probably more than a little help from SDL, which does the heavy lifting in allowing game developers to support hardware across many platforms.

Some games, such as Super Meat Boy, let you configure your gamepad due suit your needs. But not all do: Bastion and Dust: An Elysian Tale, for example, expect an Xbox 360 controller and offer no configuration options.

xboxdrv to the rescue! It lets you simulate an Xbox 360 controller using any input device, which could be a keyboard or a gamepad. (On Windows, you can use x360ce

To install in Ubuntu:

sudo apt-get install xboxdrv

To have xboxdrv replace your gamepad’s driver, you need to find out which input device it’s using, which varies per setup, and can also change when you reboot. Run this:

evtest

This should give you a list of all joystick input devices. Here’s what I got:

Available devices:
/dev/input/event17:    Twin USB Joystick
/dev/input/event18:    Twin USB Joystick

Pick one, and press some buttons on the gamepad it to see if you get a response. If that’s not it, press CTRL+C and keep trying with all the devices. In my case, it was “event17”. Unfortunately, the device number may change when you reboot with a different set of connected USB devices.

There are a lot of configuration options for xboxdrv. This is the command I use to transform my trusty old PlayStation 1 gamepad into an Xbox 360 controller:

sudo xboxdrv \
--evdev /dev/input/event17 \
--evdev-absmap ABS_X=x1,ABS_Y=y1,ABS_RZ=x2,ABS_Z=y2,ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \
--axismap -Y1=Y1,-Y2=Y2 \
--evdev-keymap BTN_TOP=x,BTN_TRIGGER=y,BTN_THUMB2=a,BTN_THUMB=b,BTN_BASE3=back,BTN_BASE4=start,BTN_BASE=lb,BTN_BASE2=rb,BTN_TOP2=lt,BTN_PINKIE=rt,BTN_BASE5=tl,BTN_BASE6=tr \
--mimic-xpad --silent

Replace “event17” with your gamepad’s device. Once it’s running, start your game. Woohoo!

Dec 31, 1969, 18:00 CST