Difference between revisions of "Gamepad"

From ArchWiki
Jump to: navigation, search
(xboxdrv with two controllers)
(Replace use of G25manage tool (which required compiling) with similar evdev-joystick tool (in community repo))
 
(191 intermediate revisions by 82 users not shown)
Line 1: Line 1:
 
[[Category:Input devices]]
 
[[Category:Input devices]]
{{Out of date}}
+
[[Category:Gaming]]
 +
[[ja:ゲームパッド]]
 +
[[ru:Gamepad]]
 
Joysticks can be a bit of a hassle to get working in Linux. Not because they are poorly supported, but simply because you need to determine which modules to load to get your joystick working, and it's not always very obvious!
 
Joysticks can be a bit of a hassle to get working in Linux. Not because they are poorly supported, but simply because you need to determine which modules to load to get your joystick working, and it's not always very obvious!
  
= Setup =
+
== Joystick input systems ==
== Determining Which Modules You Need ==
+
Linux has 2 different input systems for Joysticks. The original 'Joystick' interface and the newer 'evdev' based one.
For an extensive overview of all joystick related modules in Linux, you will need access to the Linux kernel sources -- specifically the Documentation section. Unfortunately, pacman kernel packages do not include what we need. If you have the kernel sources downloaded, have a look at <code>Documentation/input/joystick.txt</code>. You can browse the kernel source tree at [http://kernel.org/ kernel.org] by clicking the "C" (current changesets) link, then clicking the "tree" link near the top. Here's a link to the [http://www.kernel.org/git/?p=linux/kernel/git/stable/linux-2.6.17.y.git;a=blob;h=d53b857a3710ccdde5bc504f212993dcb10a20be;hb=d2350c2ad1463a973b586cadb49c2fa0c83089b8;f=Documentation/input/joystick.txt Documentation from kernel 2.6.17.11].
 
  
Some joysticks need specific modules, such as the Microsoft Sidewinder controllers (<code>sidewinder</code>), or the Logitech digital controllers (<code>adi</code>). Many older joysticks will work with the simple <code>analog</code> module. If your joystick is plugging in to a gameport provided by your soundcard, you will need your soundcard drivers loaded - however, some cards, like the Soundblaster Live, have a specific gameport driver (<code>emu10k1-gp</code>). Older ISA soundcards may need the <code>ns558</code> module, which is a standard gameport module.
+
{{ic|1=/dev/input/jsX}} maps to the 'Joystick' API interface and {{ic|/dev/input/event*}} maps to the 'evdev' ones (this also includes other input devices such as mice and keyboards). Symbolic links to those devices are also available in {{ic|/dev/input/by-id/}} and {{ic|/dev/input/by-path/}} where the legacy 'Joystick' API has names ending with {{ic|-joystick}} while the 'evdev' have names ending with {{ic|-event-joystick}}.
 +
 
 +
Most new games will default to the 'evdev' interface as it gives more detailed information about the buttons and axes available and also adds support for force feedback.
 +
 
 +
While SDL1 defaults to 'evdev' interface you can force it to use the old 'Joystick' API by setting the environment variable {{ic|1=SDL_JOYSTICK_DEVICE=/dev/input/js0}}. This can help many games such as X3. SDL2 supports only the new 'evdev' interface.
 +
 
 +
== Determining which modules you need ==
 +
 
 +
Unless you're using very old joystick that uses gameport or proprietary USB protocol, you will need just the generic USB human interface device (HID) modules.
 +
 
 +
For an extensive overview of all joystick related modules in Linux, you will need access to the Linux kernel sources -- specifically the Documentation section. Unfortunately, pacman kernel packages do not include what we need. If you have the kernel sources downloaded, have a look at {{ic|Documentation/input/joystick.txt}}. You can browse the kernel source tree at [https://kernel.org/ kernel.org] by clicking the "browse" (cgit - the git frontend) link for the kernel that you're using, then clicking the "tree" link near the top. Here's a link to the [https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/input/joystick.txt documentation from the latest kernel].
 +
 
 +
Some joysticks need specific modules, such as the Microsoft Sidewinder controllers ({{ic|sidewinder}}), or the Logitech digital controllers ({{ic|adi}}). Many older joysticks will work with the simple {{ic|analog}} module. If your joystick is plugging in to a gameport provided by your soundcard, you will need your soundcard drivers loaded - however, some cards, like the Soundblaster Live, have a specific gameport driver ({{ic|emu10k1-gp}}). Older ISA soundcards may need the {{ic|ns558}} module, which is a standard gameport module.
  
 
As you can see, there are many different modules related to getting your joystick working in Linux, so I couldn't possibly cover everything here. Please have a look at the documentation mentioned above for details.
 
As you can see, there are many different modules related to getting your joystick working in Linux, so I couldn't possibly cover everything here. Please have a look at the documentation mentioned above for details.
  
==Loading the Modules==
+
=== Loading the modules for analogue devices ===
You need to load a module for your gameport (<code>ns558</code>, <code>emu10k1-gp</code>, <code>cs461x</code>, etc...), a module for your joystick (<code>analog</code>, <code>sidewinder</code>, <code>adi</code>, etc...), and finally the kernel joystick device driver (<code>joydev</code>). Add these to your <code>/etc/rc.conf</code>, or simply modprobe them. The <code>gameport</code> module should load automatically, as this is a dependency of the other modules.
+
 
 +
You need to load a module for your gameport ({{ic|ns558}}, {{ic|emu10k1-gp}}, {{ic|cs461x}}, etc...), a module for your joystick ({{ic|analog}}, {{ic|sidewinder}}, {{ic|adi}}, etc...), and finally the kernel joystick device driver ({{ic|joydev}}). Add these to a new file in {{ic|/etc/modules-load.d/}}, or simply modprobe them. The {{ic|gameport}} module should load automatically, as this is a dependency of the other modules.
 +
 
 +
=== USB joysticks ===
 +
 
 +
You need to get USB working, and then modprobe your joystick driver, which is {{ic|usbhid}}, as well as {{ic|joydev}}.
 +
If you use a usb mouse or keyboard, {{ic|usbhid}} will be loaded already and you just have to load the {{ic|joydev}} module.
 +
 
 +
== Testing your configuration ==
 +
 
 +
Once the modules are loaded, you should be able to find a new device: {{ic|/dev/input/js0}} and a file ending with {{ic|-event-joystick}} in {{ic|/dev/input/by-id}} directory. You can simply {{ic|cat}} those devices to see if the joystick works - move the stick around, press all the buttons - you should see mojibake printed when you move the sticks or press buttons.
 +
 
 +
Both interfaces are also supported in wine and reported as separate devices. You can test them with {{ic|1=wine control joy.cpl}}.
 +
 
 +
{{Tip| Input devices by default have '''input''' group, for example {{pkg|pcsx2}} have no access to gamepad without rights. Make sure your user in '''input''' group.}}
 +
 
 +
 
 +
=== Joystick API ===
 +
There are a lot of applications that can test this old API, {{ic|jstest}} from the {{pkg|joyutils}} package is the simplest one. If the output is unreadable because the line printed is too long you can also use graphical tools. KDE4 has a built in one in Input Devices panel in System Settings or {{AUR|jstest-gtk-git}} is an alternative.
 +
 
 +
Use of {{ic|jstest}} is fairly simple, you just run {{ic|jstest /dev/input/js0}} and it will print a line with state of all the axes (normalised to {-32767,32767}) and buttons.
 +
 
 +
After you start {{ic|jstest-gtk}}, it will just show you a list of joysticks available, you just need to select one and press Properties.
 +
 
 +
=== evdev API ===
 +
 
 +
The new 'evdev' API can be tested using the SDL2 joystick test application or using {{ic|evtest}} from community repository. Install {{AUR|sdl2-jstest-git}} and then run {{ic|sdl2-jstest --test 0}}. Use {{ic|sdl2-jstest --list}} to get IDs of other controllers if you have multiple ones connected.
 +
 
 +
To test force feedback on the device, use {{ic|fftest}} from {{ic|linuxconsole}} package:
 +
$ fftest /dev/input/by-id/usb-*event-joystick
 +
 
 +
==Setting up deadzones and calibration==
 +
If you want to set up the deadzones (or remove them completely) of your analog input you have to do it separately for the xorg (for mouse and keyboard emulation), Joystick API and evdev API.
 +
 
 +
===Wine deadzones===
 +
Add the following registry entry and set it to a string from 0 to 10000 (affects all axes):
 +
HKEY_CURRENT_USER\Software\Wine\DirectInput\DefaultDeadZone
 +
Source: [http://wiki.winehq.org/UsefulRegistryKeys UsefulRegistryKeys]
 +
 
 +
===Xorg deadzones===
 +
Add a similar line to {{ic|/etc/X11/xorg.conf.d/51-joystick.conf}} (create if it doesn't exist):
 +
{{hc|1=/etc/X11/xorg.conf.d/51-joystick.conf|2=<nowiki>
 +
Section "InputClass"
 +
    Option "MapAxis1" "deadzone=1000"
 +
EndSection
 +
</nowiki>}}
 +
1000 is the default value, but you can set anything between 0 and 30 000. To get the axis number see the "Testing Your Configuration" section of this article.
 +
If you already have an option with a specific axis just type in the {{ic|1=deadzone=value}} at the end of the parameter separated by a space.
 +
 
 +
===Joystick API deadzones===
 +
The easiest way is using {{ic|jstest-gtk}} from {{AUR|jstest-gtk-git}}. Select the controller you want to edit, then click the Calibration button at the bottom of the dialog ('''don't''' click Start Calibration there). You can then set the CenterMin and CenterMax values (which control the center deadzone), RangeMin and RangeMax which control the end of throw deadzones. Note that the calibration settings are applied when the application opens the device, so you need to restart your game or test application to see updated calibration settings.
 +
 
 +
After you set the deadzones use {{ic|jscal}} to dump the new values into a shell script:
 +
$ jscal -p /dev/input/jsX > jscal.sh # replace X with your joystick's number
 +
$ chmod +x jscal.sh
 +
 
 +
Now you need to make a [[udev]] rule (for example {{ic|/etc/udev/rules.d and name it 85-jscal.rules}}) so the script will automatically run when you connect the controller:
 +
SUBSYSTEM=="input", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="c268", ACTION=="add", RUN+="/usr/bin/jscal.sh"
 +
To get the idVendor and idProduct use {{ic|udevadm info --attribute-walk --name /dev/input/jsX}}
 +
 
 +
Use the `/dev/input/by-id/*-joystick` device names in case you use multiple controllers.
 +
 
 +
===evdev API deadzones===
 +
The {{ic|evdev-joystick}} tool from the {{pkg|linuxconsole}} package can be used to view and change deadzones and calibration for {{ic|evdev}} API devices.
 +
 
 +
To view your device configuration:
 +
$ evdev-joystick --showcal /dev/input/by-id/usb-*-event-joystick
 +
 
 +
To change the deadzone for a particular axis, use a command like:
 +
$ evdev-joystick --evdev /dev/input/by-id/usb-*-event-joystick --axis 0 --deadzone 0
 +
 
 +
To set the same deadzone for all axes at once, omit the "--axis 0" option.
 +
 
 +
Use udev rules file to set them automatically when the controller is connected.
 +
 
 +
Note that inside the kernel, the value is called {{ic|flatness}} and is set using the {{ic|EVIOCSABS}} {{ic|ioctl}}.
 +
 
 +
Default configuration will look like similar to this:
 +
{{hc|$ evdev-joystick --showcal /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick|2= Supported Absolute axes:
 +
  Absolute axis 0x00 (0) (X Axis) (min: 0, max: 65535, flatness: 4095 (=6.25%), fuzz: 255)
 +
  Absolute axis 0x01 (1) (Y Axis) (min: 0, max: 65535, flatness: 4095 (=6.25%), fuzz: 255)
 +
  Absolute axis 0x05 (5) (Z Rate Axis) (min: 0, max: 4095, flatness: 255 (=6.23%), fuzz: 15)
 +
  Absolute axis 0x10 (16) (Hat zero, x axis) (min: -1, max: 1, flatness: 0 (=0.00%), fuzz: 0)
 +
  Absolute axis 0x11 (17) (Hat zero, y axis) (min: -1, max: 1, flatness: 0 (=0.00%), fuzz: 0)}}
 +
 
 +
While a more reasonable setting would be achieved with something like this (repeat for other axes):
 +
{{hc|$ evdev-joystick --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick --axis 0 --deadzone 512|2= Event device file: /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick
 +
Axis index to deal with: 0
 +
New dead zone value: 512
 +
Trying to set axis 0 deadzone to: 512
 +
  Absolute axis 0x00 (0) (X Axis) Setting deadzone value to : 512
 +
(min: 0, max: 65535, flatness: 512 (=0.78%), fuzz: 255)}}
 +
 
 +
===Configuring curves and responsivness===
 +
In case your game requires just limited amount of buttons or has good support for multiple controllers, you may have good results with using {{ic|xboxdrv}} to change response curves of the joystick.
 +
 
 +
Below are the setups I use for Saitek X-55 HOTAS:
 +
$ xboxdrv --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Throttle_G0000021-event-joystick \
 +
  --evdev-no-grab --evdev-absmap 'ABS_#40=x1,ABS_#41=y1,ABS_X=x2,ABS_Y=y2' --device-name 'Hat and throttle' \
 +
  --ui-axismap 'x2^cal:-32000:0:32000=,y2^cal:-32000:0:32000=' --silent
 +
 
 +
this maps the EV_ABS event with id of 40 and 41 (use xboxdrv with --evdev-debug to see the events registered), which is the normally inaccessible "mouse pointer" on the throttle, to first gamepad joystick and throttles to second joystick, it also clamps the top and lower ranges as they not always register fully.
 +
 
 +
A bit more interesting is the setup for the stick:
 +
$ xboxdrv --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick \
 +
  --evdev-no-grab --evdev-absmap 'ABS_X=x1' --evdev-absmap 'ABS_Y=y1' --device-name 'Joystick' \
 +
  --ui-axismap 'x1^cal:-32537:-455:32561=,x1^dead:-900:700:1=,x1^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
 +
  --ui-axismap 'y1^cal:-32539:-177:32532=,y1^dead:-700:2500:1=,y1^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
 +
  --evdev-absmap 'ABS_RZ=x2' --ui-axismap 'x2^cal:-32000:-100:32000,x2^dead:-1500:1000:1=,x2^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
 +
  --silent
 +
 
 +
this maps the 3 joystick axes to gamepad axes and changes the calibration (min value, centre value, max value), dead zones (negative side, positive side, flag to turn smoothing) and finally change of response curve to a more flat one in the middle.
 +
 
 +
You can also modify the responsiveness by setting the 'sen' (sensitivity). Setting it to value of 0 will give you a linear sensitivity, value of -1 will give very insensitive axis while value of 1 will give very sensitive axis. You can use intermediate values to make it less or more sensitive. Internally xboxdrv uses a quadratic formula to calculate the resulting value, so this setting gives a more smooth result than 'resp' shown above.
 +
 
 +
Nice thing about xboxdrv is that it exports resulting device as both old Joystick API and new style evdev API so it should be compatible with basically any application.
 +
 
 +
== Disable joystick from controlling mouse ==
 +
If you want to play games with your controller, you might want to disable joystick control over mouse cursor.  To do this, edit {{ic|/etc/X11/xorg.conf.d/51-joystick.conf}} (create if it doesn't exists) so that it looks like this:
 +
{{hc|/etc/X11/xorg.conf.d/51-joystick.conf |
 +
Section "InputClass"
 +
        Identifier "joystick catchall"
 +
        MatchIsJoystick "on"
 +
        MatchDevicePath "/dev/input/event*"
 +
        Driver "joystick"
 +
        Option "StartKeysEnabled" "False"      #Disable mouse
 +
        Option "StartMouseEnabled" "False"      #support
 +
EndSection}}
 +
 
 +
== Using Joystick to send keystrokes ==
 +
 
 +
A couple joystick to keystroke programs exist like {{AUR|qjoypad}} or {{AUR|antimicro}}, all work well without the need for X.org configuration.
 +
 
 +
=== Xorg configuration example ===
 +
 
 +
This is a good solution for systems where restarting Xorg is a rare event because it is a static configuration loaded only on X startup. The example runs on a [[Kodi]] media PC, controlled with a Logitech Cordless RumblePad 2. Due to a problem with the d-pad (a.k.a. "hat") being recognized as another axis, [[Joy2key]] was used as a workaround. Since upgrade to Kodi version 11.0 and joy2key 1.6.3-1, this setup no longer worked and the following was created for letting Xorg handle joystick events.
 +
 
 +
First, [[install]] the {{AUR|xf86-input-joystick}} package. Then, create {{ic|/etc/X11/xorg.conf.d/51-joystick.conf}} like so:
 +
{{bc|<nowiki>
 +
Section "InputClass"
 +
  Identifier "Joystick hat mapping"
 +
  Option "StartKeysEnabled" "True"
 +
  #MatchIsJoystick "on"
 +
  Option "MapAxis5" "keylow=113 keyhigh=114"
 +
  Option "MapAxis6" "keylow=111 keyhigh=116"
 +
EndSection
 +
</nowiki>}}
 +
{{Note|The {{ic|MatchIsJoystick "on"}} line does not seem to be required for the setup to work, but you may want to uncomment it.}}
 +
 
 +
== Specific devices ==
 +
 
 +
While most joysticks, especially USB based ones should just work, some may require (or give better results) if you use alternative drivers. If it doesn't work the first time, do not give up, and read those docs thoroughly!
 +
 
 +
=== Dance pads ===
 +
Most dance pads should work. However some pads, especially those used from a video game console via an adapter, have a tendency to map the directional buttons as axis buttons. This prevents hitting left-right or up-down simultaneously. This behavior can be fixed for devices recognized by xpad via a module option:
 +
 
 +
  # modprobe -r xpad
 +
  # modprobe xpad dpad_to_buttons=1
 +
 
 +
=== Logitech Thunderpad Digital ===
 +
 
 +
Logitech Thunderpad Digital won't show all the buttons if you use the {{ic|analog}} module. Use the device specific {{ic|adi}} module for this controller.
 +
 
 +
=== Nintendo Gamecube Controller ===
 +
 
 +
Dolphin Emulator has a [https://wiki.dolphin-emu.org/index.php?title=How_to_use_the_Official_GameCube_Controller_Adapter_for_Wii_U_in_Dolphin page on their wiki] that explains how to use the official Nintendo USB adapter with a Gamecube controller. This configuration also works with the Mayflash Controller Adapter if the switch is set to "Wii U".
 +
 
 +
By default, the controller will register with [[udev]], but will only be readable by the root user. You can fix this by adding a udev device rule, like the below.
 +
 
 +
{{hc
 +
|head=/etc/udev/rules.d/51-gcadapter.rules
 +
|output=<nowiki>SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0337", MODE="0666"</nowiki>
 +
}}
 +
 
 +
This only matches the USB device with the specified vendor and product IDs, which match those of the official USB adapter. It sets the permissions of the device file to 0666 so that programs that aren't running as root can read the device's input.
 +
 
 +
udev can be reloaded with the new configuration by executing
 +
                                                                 
 +
  # udevadm control --reload-rules
 +
 
 +
=== PlayStation 3/4 controller ===
 +
 
 +
The DualShock 3, DualShock 4 and Sixaxis controllers work out of the box when plugged in via USB (the PS button will need to be pushed to begin). They can also be used wirelessly via Bluetooth.
 +
 
 +
Steam properly recognizes it as a PS3 pad and Big Picture can be launched with the PS button. Big Picture and some games may act as if it was a 360 controller.  Gamepad control over mouse is on by default.  You may want to turn it off before playing games, see [[#Joystick moving mouse]].
 +
 
 +
=====Connecting via Bluetooth=====
 +
 
 +
Install the {{Pkg|bluez}}, {{Pkg|bluez-plugins}}, and {{Pkg|bluez-utils}} packages, which includes the ''sixaxis'' plugin. Then [[start]] {{ic|bluetooth.service}}, plug the controller in via USB, and the plugin should program your PC's bluetooth address into the controller automatically.
 +
 
 +
You can now disconnect your controller. The next time you hit the PlayStation button it will connect without asking anything else.
 +
 
 +
Alternatively, you can press the share button and the PlayStation button simultaneously to put the gamepad in pairing mode, and pair as you would normally.
 +
 
 +
Remember to disconnect the controller when you are done as the controller will stay on when connected and drain the battery.
 +
 
 +
{{Note|If the controller does not connect, make sure the bluetooth interface is turned on and the controllers have been trusted. (See [[Bluetooth]])}}
 +
 
 +
=== iPEGA-9017s and other Bluetooth gamepads ===
 +
 
 +
If you want to use one of the widely available bluetooth gamepads, such as iPEGA-9017s designed mostly for Android and iOS devices you would need {{AUR|xboxdrv}}, {{Pkg|bluez}}, {{Pkg|bluez-plugins}}, and {{Pkg|bluez-utils}}. You should connect it in gamepad mode (if there are different modes, choose the gamepad one). Technically it's ready to be used, but in most cases games would not recognize it, and you would have to map it individually for all application. The best way to simplify it and make it work with all applications is to mimic Microsoft X360 controller with {{AUR|xboxdrv}}.
 +
Once connected you can create a udev rule to give it a persistent name, that would come in handy when setting it up.
 +
 
 +
{{hc
 +
|/etc/udev/rules.d/99-btjoy.rules|2=
 +
#Create a symlink to appropriate /dev/input/eventX at /dev/btjoy
 +
ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="Bluetooth Gamepad", ATTRS{uniq}=="00:17:02:01:ae:2a", SYMLINK+="btjoy"
 +
}}
 +
 
 +
Replace "Bluetooth Gampad" with your device name and "00:17:02:01:ae:2a" with your device's address.
 +
 
 +
Next, create a configuration for {{AUR|xboxdrv}} somewhere, for example:
 +
 
 +
{{hc
 +
|~/.config/xboxdrv/ipega.conf|2=
 +
#iPEGA PG-9017S Config
 +
 
 +
[xboxdrv]
 +
evdev-debug = true
 +
evdev-grab = true
 +
rumble = false
 +
mimic-xpad = true
 +
 
 +
[evdev-absmap]
 +
ABS_HAT0X = dpad_x
 +
ABS_HAT0Y = dpad_y
 +
 
 +
ABS_X = X1
 +
ABS_Y = Y1
 +
 
 +
ABS_Z  = X2
 +
ABS_RZ = Y2
 +
 
 +
[axismap]
 +
-Y1 = Y1
 +
-Y2 = Y2
 +
 
 +
[evdev-keymap]
 +
BTN_EAST=a
 +
BTN_C=b
 +
BTN_NORTH=y
 +
BTN_SOUTH=x
 +
BTN_TR2=start
 +
BTN_TL2=back
 +
BTN_Z=rt
 +
BTN_WEST=lt
 +
 
 +
BTN_MODE = guide
 +
}}
 +
 
 +
Refer to the xboxdrv man to see all the options.
 +
 
 +
Now when you have the config and your device is connected you can start the {{AUR|xboxdrv}} like so:
 +
 
 +
{{ic | sudo xboxdrv --evdev /dev/btjoy --config .config/xboxdrv/ipega.conf}}
  
==Testing Your Configuration==
+
Your games will now work with bluetooth gamepad as long as xboxdrv is running.
Once the modules are loaded, you should find a new device: <code>/dev/input/js0</code>. You can simply <code>cat</code> the device to see if it works - move the stick around, press all the buttons. I found my Logitech Thunderpad Digital had two buttons that weren't working with the <code>analog</code> module. After reading some docs, I saw there was a specific <code>adi</code> module for this controller. The moral of the story is, if it doesn't work the first time, do not give up, and read those docs thoroughly! I couldn't get anything working at all until I found that documentation.
 
  
==USB Joysticks==
+
=== Steam Controller ===
You need to get USB working, and then modprobe your joystick driver, which is <code>usbhid</code>, as well as <code>joydev</code>.
 
If you use a usb mouse or keyboard, <code>usbhid</code> will be loaded already and you just have to load the <code>joydev</code> module.
 
  
==Xbox 360 Controllers==
+
The {{pkg|steam}} package (starting from version 1.0.0.51-1) will recognize the controller and provide keyboard/mouse/gamepad emulation while Steam is running. The in-game Steam overlay needs to be enabled and working in order for gamepad emulation to work. You may need to run {{ic|udevadm trigger}} with root privileges or plug the dongle out and in again, if the controller doesn't work immediately after installing and running steam. If all else fails, try restarting the computer while the dongle is plugged in.
The controllers should work without additional packages, but the wireless controller needs a wireless reciever (the charge-and-play cable can not be used for communicating with the controller). Both the wired controllers and the wireless reciever is supported by the {{ic|xpad}} kernel module.
 
  
Unfortunately xpad has problems with new wireless controllers:
+
If you can't get the Steam Controller to work, see [[#Steam Controller not pairing]].
 +
 
 +
Alternatively you can install {{AUR|python-steamcontroller-git}} to have controller and mouse emulation without Steam or {{AUR|sc-controller}} for a versatile graphical configuration tool simillar to what is provided by the steam client.
 +
 
 +
On some desktop environments the on screen keyboard might freeze when trying to input text after two characters. This is a problem with window focus. Check the settings for your [[window manager]] to see if it is possible to have focus follow the mouse or automatically focus new windows.
 +
 
 +
{{Note|If you use Steam without its [[Steam/Troubleshooting#Steam runtime issues|runtime]], you might actually need to disable the overlay for the controller to work in certain games (Rocket Wars, Rocket League, Binding of Isaac, etc.). Right click on a game in your library, select "Properties", and uncheck "Enable Steam Overlay".}}
 +
 
 +
==== Wine ====
 +
 
 +
{{AUR|python-steamcontroller-git}} can also be used to make the Steam Controller work for games running under Wine. You need to find and download the application {{ic|xbox360cemu.v.3.0}} (e.g. from here: https://github.com/jacobmischka/ds4-in-wine/tree/master/xbox360cemu.v.3.0). Then copy the files {{ic|dinput8.dll}}, {{ic|xbox360cemu.ini}}, {{ic|xinput1_3.dll}} and {{ic|xinput_9_1_0.dll}} to the directory that contains your game executable. Edit {{ic|xbox360cemu.ini}} and only change the following values under {{ic|[PAD1]}} to remap the Steam Controller correctly to a XBox Controller.
 +
 
 +
{{hc|xbox360cemu.ini|2= Right Analog X=4
 +
Right Analog Y=-5
 +
A=1
 +
B=2
 +
X=3
 +
Y=4
 +
Back=7
 +
Start=8
 +
Left Thumb=10
 +
Right Thumb=11
 +
Left Trigger=a3
 +
Right Trigger=a6}}
 +
 
 +
Now start python-steamcontroller in Xbox360 mode ({{ic|sc-xbox.py start}}). You might also want to copy {{ic|XInputTest.exe}} from {{ic|xbox360cemu.v.3.0}} to the same directory and run it with Wine in order to test if the mappings work correctly. However neither mouse nor keyboard emulation work with this method.
 +
 
 +
Alternatively you can use {{AUR|sc-controller}} ([https://github.com/kozec/sc-controller github]) for a similar graphical setup as steams own configurator. As of writing, it's a bit buggy here and there but offers an easy click and go way of configuring the controller.
 +
 
 +
=== Xbox 360 controller ===
 +
 
 +
Both the wired and wireless (with the ''Xbox 360 Wireless Receiver for Windows'') controllers are supported by the {{ic|xpad}} kernel module and should work without additional packages.
 +
 
 +
It has been reported that the default xpad driver has some issues with a few newer wired and wireless controllers, such as:
 
* incorrect button mapping. ([https://github.com/ValveSoftware/steam-for-linux/issues/95#issuecomment-14009081 discussion in Steam bugtracker])
 
* incorrect button mapping. ([https://github.com/ValveSoftware/steam-for-linux/issues/95#issuecomment-14009081 discussion in Steam bugtracker])
 
* not-working sync. All four leds keep blinking, but controller works. ([https://bbs.archlinux.org/viewtopic.php?id=156028 discussion in Arch Forum])
 
* not-working sync. All four leds keep blinking, but controller works. ([https://bbs.archlinux.org/viewtopic.php?id=156028 discussion in Arch Forum])
The working solution is use {{aur|xboxdrv}}. It is alternative driver wich works in userspace. It could be launched as system service.
 
  
If you wish to use the controller for controlling the mouse, or mapping buttons to keys, etc. you should use the {{ic|xf86-input-joystick}} package (configuration help can be found using {{ic|man joystick}}). If the mouse locks itself in a corner, it might help changing the {{ic|MatchDevicePath}} in {{ic|/etc/X11/xorg.conf.d/50-joystick.conf}} from {{ic|/dev/input/event*}} to {{ic|/dev/input/js*}}.
+
If you experience such issues, you can use either [[#SteamOS xpad]] or [[#xboxdrv]] instead of the default {{ic|xpad}} driver.
 +
 
 +
If you wish to use the controller for controlling the mouse, or mapping buttons to keys, etc. you should use the {{AUR|xf86-input-joystick}} package (configuration help can be found using {{ic|man joystick}}). If the mouse locks itself in a corner, it might help changing the {{ic|MatchDevicePath}} in {{ic|/etc/X11/xorg.conf.d/50-joystick.conf}} from {{ic|/dev/input/event*}} to {{ic|/dev/input/js*}}.
 +
 
 +
{{Tip|If you use the [[TLP]] power management tool, you may experience connection issues with your Microsoft wireless adapter (e.g. the indicator LED will go out after the adapter has been connected for a few seconds, and controller connection attempts fail). This is due to TLP's USB autosuspend functionality, and the solution is to add the Microsoft wireless adapter's device ID to this feature's blacklist (USB_BLACKLIST, check [http://linrunner.de/en/tlp/docs/tlp-configuration.html#usb TLP configuration] for more details).}}
 +
 
 +
==== SteamOS xpad ====
 +
 
 +
If you have issues with the default {{ic|xpad}} kernel module, you can install the SteamOS version. There is still a known issue with compatibility between wireless Xbox360 controllers and games made in GameMaker Studio. If you encounter this problem, the only known workaround is to use xboxdrv. YoYo Games has refused to acknowledge this as a bug with their product and it is unlikely to ever be fixed.
 +
 
 +
First make sure you have [[DKMS]] installed and running, then install the modified kernel module {{AUR|steamos-xpad-dkms}}. During the installation you'll see that new xpad kernel module is strapped to your current kernel:
 +
 
 +
Creating symlink /var/lib/dkms/steamos-xpad-dkms/0.1/source -&gt;
 +
                  /usr/src/steamos-xpad-dkms-0.1
 +
 
 +
DKMS: add completed.
 +
 
 +
Kernel preparation unnecessary for this kernel.  Skipping...
 +
 
 +
Building module:
 +
cleaning build area....
 +
make KERNELRELEASE=3.12.8-1-ARCH KVERSION=3.12.8-1-ARCH....
 +
cleaning build area....
 +
 
 +
Then unload the old xpad module and load new one:
 +
 
 +
# rmmod xpad
 +
# modprobe steamos-xpad
 +
 
 +
Or just restart your computer.
 +
 
 +
==== xboxdrv ====
  
===xboxdrv with two controllers===
+
xboxdrv is an alternative to {{ic|xpad}} which provides more functionality and might work better with certain controllers. It works in userspace and can be launched as system service.
xboxdrv supports a multitude of controllers, but it works only in [http://pingus.seul.org/~grumbel/xboxdrv/xboxdrv.html#idp147464 daemon mode].
+
 
The simplest way is launch xboxdrv as service in daemon mode:
+
Install it with the {{AUR|xboxdrv}} package. Then [[start]]/[[enable]] {{ic|xboxdrv.service}}.
ExecStart = /usr/bin/xboxdrv -D -c /etc/conf.d/xboxdrv
+
 
And add support of the second controller in config file:
+
If you have issues with the controller being recognized but not working in steam games or working but with incorrect mappings, it may be required to modify you config as such:
 +
{{hc
 +
|/etc/default/xboxdrv/|2=
 +
[xboxdrv]
 +
silent = true
 +
device-name = "Xbox 360 Wireless Receiver"
 +
mimic-xpad = true
 +
deadzone = 4000
 +
 
 +
[xboxdrv-daemon]
 +
dbus = disabled
 +
}}
 +
 
 +
Then [[restart]] {{ic|xboxdrv.service}}.
 +
 
 +
===== Multiple controllers =====
 +
 
 +
xboxdrv supports a multitude of controllers, but they need to be set up in {{ic|/etc/default/xboxdrv}}. For each extra controller, add an {{ic|1=next-controller = true}} line. For example, when using 4 controllers, add it 3 times:
 +
 
 +
{{bc|<nowiki>
 
  [xboxdrv]
 
  [xboxdrv]
 
  silent = true
 
  silent = true
 +
next-controller = true
 +
next-controller = true
 
  next-controller = true
 
  next-controller = true
 
  [xboxdrv-daemon]
 
  [xboxdrv-daemon]
 
  dbus = disabled
 
  dbus = disabled
 +
</nowiki>}}
 +
 +
Then [[restart]] {{ic|xboxdrv.service}}.
 +
 +
===== Mimic Xbox 360 controller with other controllers =====
 +
 +
xboxdrv can be used to make any controller register as an Xbox 360 controller with the {{ic|--mimic-xpad}} switch. This may be desirable for games that support Xbox 360 controllers out of the box, but have trouble detecting or working with other gamepads.
 +
 +
First, you need to find out what each button and axis on the controller is called. You can use {{Pkg|evtest}} for this. Run {{ic|evtest}} and select the device event ID number ({{ic|/dev/input/event*}}) that corresponds to your controller. Press the buttons on the controller and move the axes to read the names of each button and axis.
  
==Troubleshooting==
+
Here is an example of the output:
 +
{{bc|<nowiki>
  
===Joystick moving mouse===
+
Event: time 1380985017.964843, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90003
Sometimes USB joystick can be recognized as HID mouse (only in X, it is still being installed as /dev/input/js0 as well). Known issue is cursor being moved by the joystick, or escaping to en edge of a screen right after plugin. If your application can detect joystick by it self, you can remove xf86-input-joystick package:
+
Event: time 1380985017.964843, type 1 (EV_KEY), code 290 (BTN_THUMB2), value 1
 +
Event: time 1380985017.964843, -------------- SYN_REPORT ------------
 +
Event: time 1380985018.076843, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90003
 +
Event: time 1380985018.076843, type 1 (EV_KEY), code 290 (BTN_THUMB2), value 0
 +
Event: time 1380985018.076843, -------------- SYN_REPORT ------------
 +
Event: time 1380985018.460841, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
 +
Event: time 1380985018.460841, type 1 (EV_KEY), code 289 (BTN_THUMB), value 1
 +
Event: time 1380985018.460841, -------------- SYN_REPORT ------------
 +
Event: time 1380985018.572835, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
 +
Event: time 1380985018.572835, type 1 (EV_KEY), code 289 (BTN_THUMB), value 0
 +
Event: time 1380985018.572835, -------------- SYN_REPORT ------------
 +
Event: time 1380985019.980824, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90006
 +
Event: time 1380985019.980824, type 1 (EV_KEY), code 293 (BTN_PINKIE), value 1
 +
Event: time 1380985019.980824, -------------- SYN_REPORT ------------
 +
Event: time 1380985020.092835, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90006
 +
Event: time 1380985020.092835, type 1 (EV_KEY), code 293 (BTN_PINKIE), value 0
 +
Event: time 1380985020.092835, -------------- SYN_REPORT ------------
 +
Event: time 1380985023.596806, type 3 (EV_ABS), code 3 (ABS_RX), value 18
 +
Event: time 1380985023.596806, -------------- SYN_REPORT ------------
 +
Event: time 1380985023.612811, type 3 (EV_ABS), code 3 (ABS_RX), value 0
 +
Event: time 1380985023.612811, -------------- SYN_REPORT ------------
 +
Event: time 1380985023.708768, type 3 (EV_ABS), code 3 (ABS_RX), value 14
 +
Event: time 1380985023.708768, -------------- SYN_REPORT ------------
 +
Event: time 1380985023.724772, type 3 (EV_ABS), code 3 (ABS_RX), value 128
 +
Event: time 1380985023.724772, -------------- SYN_REPORT ------------
 +
</nowiki>}}
  
# pacman -R xf86-input-joystick
+
In this case, {{ic|BTN_THUMB}}, {{ic|BTN_THUMB2}} and {{ic|BTN_PINKIE}} are buttons and {{ic|ABS_RX}} is the X axis of the right analogue stick.
 +
You can now mimic an Xbox 360 controller with the following command:
  
More gentle solution is to add:
+
$ xboxdrv --evdev /dev/input/event* --evdev-absmap ABS_RX=X2 --evdev-keymap BTN_THUMB2=a,BTN_THUMB=b,BTN_PINKIE=rt --mimic-xpad
  
Option "StartKeysEnabled" "False"
+
The above example is incomplete. It only maps one axis and 3 buttons for demonstration purposes. Use {{ic|xboxdrv --help-button}} to see the names of the Xbox controller buttons and axes and bind them accordingly by expanding the command above. Axes mappings should go after {{ic|--evdev-absmap}} and button mappings follow {{ic|--evdev-keymap}} (comma separated list; no spaces).
Option "StartMouseEnabled" "False"
 
  
at the end of your {{ic|/etc/X11/xorg.conf.d/50-joystick.conf}} of joystick {{ic|InputClass}}.
+
By default, xboxdrv outputs all events to the terminal. You can use this to test that the mappings are correct. Append the {{ic|--silent}} option to keep it quiet.
  
===Joystick sending keystrokes===
+
======Logitech Dual Action======
This is a good solution for systems where restarting Xorg is a rare event because it's a static configuration loaded only on X startup. I use it on my media PC running XBMC controlled with Logitech Cordless RumblePad 2. Due to a problem with the d-pad (a.k.a. "hat") being recognized as another axis, I used to run [[Joy2key]] as a workaround. Since I upgraded to XBMC 11.0 and joy2key 1.6.3-1, this setup no longer worked for me. I ended up taking a more direct approach and let Xorg handle joystick events.
 
  
 +
The Logitech Dual Action gamepad has a very similar mapping to the PS2 pad, but some buttons and triggers need to be swapped to mimic the Xbox controller.
  
First, make sure you have {{pkg|xf86-input-joystick}} installed. Then, create {{ic|/etc/X11/xorg.conf.d/51-joystick.conf}} like so:
+
  # xboxdrv --evdev /dev/input/event* \
  Section "InputClass"
+
    --evdev-absmap ABS_X=x1,ABS_Y=y1,ABS_RZ=x2,ABS_Z=y2,ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \
Identifier "Joystick hat mapping"
+
    --axismap -Y1=Y1,-Y2=Y2 \
Option "StartKeysEnabled" "True"
+
    --evdev-keymap BTN_TRIGGER=x,BTN_TOP=y,BTN_THUMB=a,BTN_THUMB2=b,BTN_BASE3=back,BTN_BASE4=start,BTN_BASE=lt,BTN_BASE2=rt,BTN_TOP2=lb,BTN_PINKIE=rb,BTN_BASE5=tl,BTN_BASE6=tr \
#MatchIsJoystick "on"
+
    --mimic-xpad --silent
Option "MapAxis5" "keylow=113 keyhigh=114"
+
 
Option "MapAxis6" "keylow=111 keyhigh=116"
+
======PlayStation 2 controller via USB adapter======
EndSection
+
 
{{Note|The <em>MatchIsJoystick "on"</em> line doesn't seem to be required for this to work but you may want to uncomment it.}}
+
To fix the button mapping of PS2 dual adapters and mimic the Xbox controller you can run the following command:
 +
 
 +
  # xboxdrv --evdev /dev/input/event* \
 +
    --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
 +
 
 +
======PlayStation 3 controller via USB======
 +
 
 +
If you own a PS3 controller and can connect with USB, xboxdrv has the mappings built in. Just run the program (and detach the running driver) and it works!
 +
 
 +
# xboxdrv --silent --detach-kernel-driver
 +
 
 +
There are some games which might also need the {{ic|--mimic-xpad}} option, additionally.
 +
 
 +
======PlayStation 3 controller via Bluetooth======
 +
 
 +
With your controller connected via Bluetooth, find the device address with {{ic|bluetoothctl}}. Then create a new udev rule with the following content:
 +
 
 +
{{hc|1=/etc/udev/rules.d/99-dualshock.rules|2=
 +
KERNEL=="event*", SUBSYSTEM=="input", ATTRS{uniq}=="<device_addr_you_got_on_pairing>", SYMLINK+="input/dualshock3"
 +
}}
 +
 
 +
The address must be in lowercase, like {{ic|06:9a:b4:c8:ef:8b}}.
 +
 
 +
Now run xboxdrv over the new device:
 +
 
 +
  $ xboxdrv --evdev /dev/input/dualshock3 --mimic-xpad
 +
 
 +
======PlayStation 4 controller======
 +
 
 +
To fix the button mapping of PS4 controller you can use the following command with xboxdrv (or try with the [https://github.com/chrippa/ds4drv ds4drv] program):
 +
                                                                                                                       
 +
  # xboxdrv \
 +
    --evdev /dev/input/by-id/usb-Sony_Computer_Entertainment_Wireless_Controller-event-joystick\
 +
    --evdev-absmap ABS_X=x1,ABS_Y=y1                \
 +
    --evdev-absmap ABS_Z=x2,ABS_RZ=y2                \
 +
    --evdev-absmap ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \
 +
    --evdev-keymap BTN_A=x,BTN_B=a                  \
 +
    --evdev-keymap BTN_C=b,BTN_X=y                  \
 +
    --evdev-keymap BTN_Y=lb,BTN_Z=rb                \
 +
    --evdev-keymap BTN_TL=lt,BTN_TR=rt              \
 +
    --evdev-keymap BTN_SELECT=tl,BTN_START=tr        \
 +
    --evdev-keymap BTN_TL2=back,BTN_TR2=start        \
 +
    --evdev-keymap BTN_MODE=guide                    \
 +
    --axismap -y1=y1,-y2=y2                          \
 +
    --mimic-xpad                                    \
 +
    --silent
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== Joystick moving mouse ===
 +
 
 +
Sometimes USB joystick can be recognized as HID mouse (only in X, it is still being installed as {{ic|/dev/input/js0}} as well). Known issue is cursor being moved by the joystick, or escaping to en edge of a screen right after plugin. If your application can detect joystick by it self, you can remove the {{AUR|xf86-input-joystick}} package.
 +
 
 +
A more gentle solution is described in [[#Disable joystick from controlling mouse]].
 +
 
 +
=== Joystick not working in FNA/SDL based games ===
 +
If you are using a generic non-widely used gamepad you may encounter issues getting the gamepad recognized in games based on SDL. Since [https://github.com/flibitijibibo/FNA/commit/e55742cfe7e38b778a21ed8a12cb2f2081490d8d 14 May 2015], FNA supports dropping a {{ic|gamecontrollerdb.txt }} into the executable folder of the game, for example the [https://github.com/gabomdq/SDL_GameControllerDB SDL_GameControllerDB].
 +
 
 +
As an alternative and for older versions of FNA or for SDL you can generate a mapping yourself by downloading the SDL source code via http://libsdl.org/, navigating to {{ic|/test/}}, compile the {{ic|controllermap.c}} program (alternatively install {{AUR|controllermap}}) and run the test. After completing the controllermap test, a guid will be generated that you can put in the {{ic|SDL_GAMECONTROLLERCONFIG}} environment variable which will then be picked up by SDL/FNA games. For example:
 +
 
 +
  $ export SDL_GAMECONTROLLERCONFIG="030000008f0e00000300000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,"
 +
 
 +
=== Joystick not recognized by all programs ===
 +
 
 +
Some software, Steam for example, will only recognize the first joystick it encounters. Due to a bug in the driver for Microsoft wireless periphery devices this can in fact be the bluetooth dongle. If you find you have a {{ic|/dev/input/js*}} and {{ic|/dev/input/event*}} belonging to you keyboard's bluetooth transceiver you can get automatically get rid of it by creating according udev rules.
 +
Create a {{ic|/}}:
 +
{{hc|/etc/udev/rules.d/99-btcleanup.rules|<nowiki>
 +
ACTION=="add", KERNEL=="js[0-9]*", SUBSYSTEM=="input", KERNELS=="...", ATTRS{bInterfaceSubClass}=="00", ATTRS{bInterfaceProtocol}=="00", ATTRS{bInterfaceNumber}=="02", RUN+="/usr/bin/rm /dev/input/js%n"
 +
ACTION=="add", KERNEL=="event*", SUBSYSTEM=="input", KERNELS=="...", ATTRS{bInterfaceSubClass}=="00", ATTRS{bInterfaceProtocol}=="00", ATTRS{bInterfaceNumber}=="02", RUN+="/usr/bin/rm /dev/input/event%n"
 +
</nowiki>}}
 +
Correct the {{ic|<nowiki>KERNELS=="..."</nowiki>}} to match your device. The correct value can be found by running
 +
 
 +
# udevadm info -an /dev/input/js0
 +
 
 +
Assuming the device in question is {{ic|/dev/input/js0}}. After you placed the rule reload the rules with
 +
 
 +
# udevadm control --reload
 +
 
 +
Then replug the device making you trouble. The joystick and event devices should be gone, although their number will still be reserved. But the files are out of the way.
 +
 
 +
=== Steam Controller not pairing ===
 +
 
 +
There are some unknown cases where the packaged udev rule for the Steam controller does not work ({{bug|47330}}). The most reliable workaround is to make the controller world readable. Copy the rule {{ic|/usr/lib/udev/rules.d/80-steam-controller-permission.rule}} to {{ic|/etc/udev/rules.d}} and set {{ic|1=MODE="0666"}} e.g.
 +
 
 +
{{hc|/etc/udev/rules.d/80-steam-controller-permission.rule|2=#USB devices
 +
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666", TAG+="uaccess"
 +
KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"}}
 +
 
 +
If you want your system to recognize the Steam controller after hot-swapping wireless/wired connections or when connected via micro-USB cable with the dongle plugged in, you may need a more complicated udev rule. Otherwise, the controller might stop working or behave like a mouse and keyboard after hot-swapping. The following rule was suggested by a Valve developer [https://steamcommunity.com/app/353370/discussions/0/490123197956024380/] which is also included in the package {{ic|steam-devices}}
 +
 
 +
{{hc|/etc/udev/rules.d/99-steam-controller-perms.rules|<nowiki>
 +
# This rule is needed for basic functionality of the controller in Steam and keyboard/mouse emulation
 +
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"
 +
 
 +
# This rule is necessary for gamepad emulation
 +
KERNEL=="uinput", MODE="0660", GROUP="steamcontroller", OPTIONS+="static_node=uinput"
 +
 
 +
# DualShock 4 wired
 +
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE="0666"
 +
# DualShock 4 wireless adapter
 +
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ba0", MODE="0666"
 +
# DualShock 4 slim wired
 +
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", MODE="0666"
 +
 
 +
# Valve HID devices over USB hidraw
 +
KERNEL=="hidraw*", ATTRS{idVendor}=="28de", MODE="0666"
 +
 
 +
# Valve HID devices over bluetooth hidraw
 +
KERNEL=="hidraw*", KERNELS=="*28DE:*", MODE="0666"
 +
 
 +
# DualShock 4 over bluetooth hidraw
 +
KERNEL=="hidraw*", KERNELS=="*054C:05C4*", MODE="0666"
 +
 
 +
# DualShock 4 Slim over bluetooth hidraw
 +
KERNEL=="hidraw*", KERNELS=="*054C:09CC*", MODE="0666"
 +
</nowiki>}}
 +
 
 +
Create a group of steam controller users.
 +
 
 +
# groupadd steamcontroller
 +
 
 +
And add your user to that group.
 +
 
 +
# gpasswd -a $USER steamcontroller

Latest revision as of 23:15, 31 August 2017

Joysticks can be a bit of a hassle to get working in Linux. Not because they are poorly supported, but simply because you need to determine which modules to load to get your joystick working, and it's not always very obvious!

Joystick input systems

Linux has 2 different input systems for Joysticks. The original 'Joystick' interface and the newer 'evdev' based one.

/dev/input/jsX maps to the 'Joystick' API interface and /dev/input/event* maps to the 'evdev' ones (this also includes other input devices such as mice and keyboards). Symbolic links to those devices are also available in /dev/input/by-id/ and /dev/input/by-path/ where the legacy 'Joystick' API has names ending with -joystick while the 'evdev' have names ending with -event-joystick.

Most new games will default to the 'evdev' interface as it gives more detailed information about the buttons and axes available and also adds support for force feedback.

While SDL1 defaults to 'evdev' interface you can force it to use the old 'Joystick' API by setting the environment variable SDL_JOYSTICK_DEVICE=/dev/input/js0. This can help many games such as X3. SDL2 supports only the new 'evdev' interface.

Determining which modules you need

Unless you're using very old joystick that uses gameport or proprietary USB protocol, you will need just the generic USB human interface device (HID) modules.

For an extensive overview of all joystick related modules in Linux, you will need access to the Linux kernel sources -- specifically the Documentation section. Unfortunately, pacman kernel packages do not include what we need. If you have the kernel sources downloaded, have a look at Documentation/input/joystick.txt. You can browse the kernel source tree at kernel.org by clicking the "browse" (cgit - the git frontend) link for the kernel that you're using, then clicking the "tree" link near the top. Here's a link to the documentation from the latest kernel.

Some joysticks need specific modules, such as the Microsoft Sidewinder controllers (sidewinder), or the Logitech digital controllers (adi). Many older joysticks will work with the simple analog module. If your joystick is plugging in to a gameport provided by your soundcard, you will need your soundcard drivers loaded - however, some cards, like the Soundblaster Live, have a specific gameport driver (emu10k1-gp). Older ISA soundcards may need the ns558 module, which is a standard gameport module.

As you can see, there are many different modules related to getting your joystick working in Linux, so I couldn't possibly cover everything here. Please have a look at the documentation mentioned above for details.

Loading the modules for analogue devices

You need to load a module for your gameport (ns558, emu10k1-gp, cs461x, etc...), a module for your joystick (analog, sidewinder, adi, etc...), and finally the kernel joystick device driver (joydev). Add these to a new file in /etc/modules-load.d/, or simply modprobe them. The gameport module should load automatically, as this is a dependency of the other modules.

USB joysticks

You need to get USB working, and then modprobe your joystick driver, which is usbhid, as well as joydev. If you use a usb mouse or keyboard, usbhid will be loaded already and you just have to load the joydev module.

Testing your configuration

Once the modules are loaded, you should be able to find a new device: /dev/input/js0 and a file ending with -event-joystick in /dev/input/by-id directory. You can simply cat those devices to see if the joystick works - move the stick around, press all the buttons - you should see mojibake printed when you move the sticks or press buttons.

Both interfaces are also supported in wine and reported as separate devices. You can test them with wine control joy.cpl.

Tip: Input devices by default have input group, for example pcsx2 have no access to gamepad without rights. Make sure your user in input group.


Joystick API

There are a lot of applications that can test this old API, jstest from the joyutils package is the simplest one. If the output is unreadable because the line printed is too long you can also use graphical tools. KDE4 has a built in one in Input Devices panel in System Settings or jstest-gtk-gitAUR is an alternative.

Use of jstest is fairly simple, you just run jstest /dev/input/js0 and it will print a line with state of all the axes (normalised to {-32767,32767}) and buttons.

After you start jstest-gtk, it will just show you a list of joysticks available, you just need to select one and press Properties.

evdev API

The new 'evdev' API can be tested using the SDL2 joystick test application or using evtest from community repository. Install sdl2-jstest-gitAUR and then run sdl2-jstest --test 0. Use sdl2-jstest --list to get IDs of other controllers if you have multiple ones connected.

To test force feedback on the device, use fftest from linuxconsole package:

$ fftest /dev/input/by-id/usb-*event-joystick

Setting up deadzones and calibration

If you want to set up the deadzones (or remove them completely) of your analog input you have to do it separately for the xorg (for mouse and keyboard emulation), Joystick API and evdev API.

Wine deadzones

Add the following registry entry and set it to a string from 0 to 10000 (affects all axes):

HKEY_CURRENT_USER\Software\Wine\DirectInput\DefaultDeadZone

Source: UsefulRegistryKeys

Xorg deadzones

Add a similar line to /etc/X11/xorg.conf.d/51-joystick.conf (create if it doesn't exist):

/etc/X11/xorg.conf.d/51-joystick.conf
Section "InputClass"
    Option "MapAxis1" "deadzone=1000"
EndSection

1000 is the default value, but you can set anything between 0 and 30 000. To get the axis number see the "Testing Your Configuration" section of this article. If you already have an option with a specific axis just type in the deadzone=value at the end of the parameter separated by a space.

Joystick API deadzones

The easiest way is using jstest-gtk from jstest-gtk-gitAUR. Select the controller you want to edit, then click the Calibration button at the bottom of the dialog (don't click Start Calibration there). You can then set the CenterMin and CenterMax values (which control the center deadzone), RangeMin and RangeMax which control the end of throw deadzones. Note that the calibration settings are applied when the application opens the device, so you need to restart your game or test application to see updated calibration settings.

After you set the deadzones use jscal to dump the new values into a shell script:

$ jscal -p /dev/input/jsX > jscal.sh # replace X with your joystick's number 
$ chmod +x jscal.sh

Now you need to make a udev rule (for example /etc/udev/rules.d and name it 85-jscal.rules) so the script will automatically run when you connect the controller:

SUBSYSTEM=="input", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="c268", ACTION=="add", RUN+="/usr/bin/jscal.sh"

To get the idVendor and idProduct use udevadm info --attribute-walk --name /dev/input/jsX

Use the `/dev/input/by-id/*-joystick` device names in case you use multiple controllers.

evdev API deadzones

The evdev-joystick tool from the linuxconsole package can be used to view and change deadzones and calibration for evdev API devices.

To view your device configuration:

$ evdev-joystick --showcal /dev/input/by-id/usb-*-event-joystick

To change the deadzone for a particular axis, use a command like:

$ evdev-joystick --evdev /dev/input/by-id/usb-*-event-joystick --axis 0 --deadzone 0

To set the same deadzone for all axes at once, omit the "--axis 0" option.

Use udev rules file to set them automatically when the controller is connected.

Note that inside the kernel, the value is called flatness and is set using the EVIOCSABS ioctl.

Default configuration will look like similar to this:

$ evdev-joystick --showcal /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick
Supported Absolute axes:
   Absolute axis 0x00 (0) (X Axis) (min: 0, max: 65535, flatness: 4095 (=6.25%), fuzz: 255)
   Absolute axis 0x01 (1) (Y Axis) (min: 0, max: 65535, flatness: 4095 (=6.25%), fuzz: 255)
   Absolute axis 0x05 (5) (Z Rate Axis) (min: 0, max: 4095, flatness: 255 (=6.23%), fuzz: 15)
   Absolute axis 0x10 (16) (Hat zero, x axis) (min: -1, max: 1, flatness: 0 (=0.00%), fuzz: 0)
   Absolute axis 0x11 (17) (Hat zero, y axis) (min: -1, max: 1, flatness: 0 (=0.00%), fuzz: 0)

While a more reasonable setting would be achieved with something like this (repeat for other axes):

$ evdev-joystick --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick --axis 0 --deadzone 512
Event device file: /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick
 Axis index to deal with: 0
 New dead zone value: 512
 Trying to set axis 0 deadzone to: 512
   Absolute axis 0x00 (0) (X Axis) Setting deadzone value to : 512
 (min: 0, max: 65535, flatness: 512 (=0.78%), fuzz: 255)

Configuring curves and responsivness

In case your game requires just limited amount of buttons or has good support for multiple controllers, you may have good results with using xboxdrv to change response curves of the joystick.

Below are the setups I use for Saitek X-55 HOTAS:

$ xboxdrv --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Throttle_G0000021-event-joystick \
  --evdev-no-grab --evdev-absmap 'ABS_#40=x1,ABS_#41=y1,ABS_X=x2,ABS_Y=y2' --device-name 'Hat and throttle' \
  --ui-axismap 'x2^cal:-32000:0:32000=,y2^cal:-32000:0:32000=' --silent

this maps the EV_ABS event with id of 40 and 41 (use xboxdrv with --evdev-debug to see the events registered), which is the normally inaccessible "mouse pointer" on the throttle, to first gamepad joystick and throttles to second joystick, it also clamps the top and lower ranges as they not always register fully.

A bit more interesting is the setup for the stick:

$ xboxdrv --evdev /dev/input/by-id/usb-Madcatz_Saitek_Pro_Flight_X-55_Rhino_Stick_G0000090-event-joystick \
  --evdev-no-grab --evdev-absmap 'ABS_X=x1' --evdev-absmap 'ABS_Y=y1' --device-name 'Joystick' \
  --ui-axismap 'x1^cal:-32537:-455:32561=,x1^dead:-900:700:1=,x1^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
  --ui-axismap 'y1^cal:-32539:-177:32532=,y1^dead:-700:2500:1=,y1^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
  --evdev-absmap 'ABS_RZ=x2' --ui-axismap 'x2^cal:-32000:-100:32000,x2^dead:-1500:1000:1=,x2^resp:-32768:-21845:-2000:0:2000:21485:32767=' \
  --silent

this maps the 3 joystick axes to gamepad axes and changes the calibration (min value, centre value, max value), dead zones (negative side, positive side, flag to turn smoothing) and finally change of response curve to a more flat one in the middle.

You can also modify the responsiveness by setting the 'sen' (sensitivity). Setting it to value of 0 will give you a linear sensitivity, value of -1 will give very insensitive axis while value of 1 will give very sensitive axis. You can use intermediate values to make it less or more sensitive. Internally xboxdrv uses a quadratic formula to calculate the resulting value, so this setting gives a more smooth result than 'resp' shown above.

Nice thing about xboxdrv is that it exports resulting device as both old Joystick API and new style evdev API so it should be compatible with basically any application.

Disable joystick from controlling mouse

If you want to play games with your controller, you might want to disable joystick control over mouse cursor. To do this, edit /etc/X11/xorg.conf.d/51-joystick.conf (create if it doesn't exists) so that it looks like this:

/etc/X11/xorg.conf.d/51-joystick.conf 
Section "InputClass"
        Identifier "joystick catchall"
        MatchIsJoystick "on"
        MatchDevicePath "/dev/input/event*"
        Driver "joystick"
        Option "StartKeysEnabled" "False"       #Disable mouse
        Option "StartMouseEnabled" "False"      #support
EndSection

Using Joystick to send keystrokes

A couple joystick to keystroke programs exist like qjoypadAUR or antimicroAUR, all work well without the need for X.org configuration.

Xorg configuration example

This is a good solution for systems where restarting Xorg is a rare event because it is a static configuration loaded only on X startup. The example runs on a Kodi media PC, controlled with a Logitech Cordless RumblePad 2. Due to a problem with the d-pad (a.k.a. "hat") being recognized as another axis, Joy2key was used as a workaround. Since upgrade to Kodi version 11.0 and joy2key 1.6.3-1, this setup no longer worked and the following was created for letting Xorg handle joystick events.

First, install the xf86-input-joystickAUR package. Then, create /etc/X11/xorg.conf.d/51-joystick.conf like so:

 Section "InputClass"
  Identifier "Joystick hat mapping"
  Option "StartKeysEnabled" "True"
  #MatchIsJoystick "on"
  Option "MapAxis5" "keylow=113 keyhigh=114"
  Option "MapAxis6" "keylow=111 keyhigh=116"
 EndSection
Note: The MatchIsJoystick "on" line does not seem to be required for the setup to work, but you may want to uncomment it.

Specific devices

While most joysticks, especially USB based ones should just work, some may require (or give better results) if you use alternative drivers. If it doesn't work the first time, do not give up, and read those docs thoroughly!

Dance pads

Most dance pads should work. However some pads, especially those used from a video game console via an adapter, have a tendency to map the directional buttons as axis buttons. This prevents hitting left-right or up-down simultaneously. This behavior can be fixed for devices recognized by xpad via a module option:

 # modprobe -r xpad
 # modprobe xpad dpad_to_buttons=1

Logitech Thunderpad Digital

Logitech Thunderpad Digital won't show all the buttons if you use the analog module. Use the device specific adi module for this controller.

Nintendo Gamecube Controller

Dolphin Emulator has a page on their wiki that explains how to use the official Nintendo USB adapter with a Gamecube controller. This configuration also works with the Mayflash Controller Adapter if the switch is set to "Wii U".

By default, the controller will register with udev, but will only be readable by the root user. You can fix this by adding a udev device rule, like the below.

/etc/udev/rules.d/51-gcadapter.rules
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0337", MODE="0666"

This only matches the USB device with the specified vendor and product IDs, which match those of the official USB adapter. It sets the permissions of the device file to 0666 so that programs that aren't running as root can read the device's input.

udev can be reloaded with the new configuration by executing

 # udevadm control --reload-rules

PlayStation 3/4 controller

The DualShock 3, DualShock 4 and Sixaxis controllers work out of the box when plugged in via USB (the PS button will need to be pushed to begin). They can also be used wirelessly via Bluetooth.

Steam properly recognizes it as a PS3 pad and Big Picture can be launched with the PS button. Big Picture and some games may act as if it was a 360 controller. Gamepad control over mouse is on by default. You may want to turn it off before playing games, see #Joystick moving mouse.

Connecting via Bluetooth

Install the bluez, bluez-plugins, and bluez-utils packages, which includes the sixaxis plugin. Then start bluetooth.service, plug the controller in via USB, and the plugin should program your PC's bluetooth address into the controller automatically.

You can now disconnect your controller. The next time you hit the PlayStation button it will connect without asking anything else.

Alternatively, you can press the share button and the PlayStation button simultaneously to put the gamepad in pairing mode, and pair as you would normally.

Remember to disconnect the controller when you are done as the controller will stay on when connected and drain the battery.

Note: If the controller does not connect, make sure the bluetooth interface is turned on and the controllers have been trusted. (See Bluetooth)

iPEGA-9017s and other Bluetooth gamepads

If you want to use one of the widely available bluetooth gamepads, such as iPEGA-9017s designed mostly for Android and iOS devices you would need xboxdrvAUR, bluez, bluez-plugins, and bluez-utils. You should connect it in gamepad mode (if there are different modes, choose the gamepad one). Technically it's ready to be used, but in most cases games would not recognize it, and you would have to map it individually for all application. The best way to simplify it and make it work with all applications is to mimic Microsoft X360 controller with xboxdrvAUR. Once connected you can create a udev rule to give it a persistent name, that would come in handy when setting it up.

/etc/udev/rules.d/99-btjoy.rules
#Create a symlink to appropriate /dev/input/eventX at /dev/btjoy
ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="Bluetooth Gamepad", ATTRS{uniq}=="00:17:02:01:ae:2a", SYMLINK+="btjoy"

Replace "Bluetooth Gampad" with your device name and "00:17:02:01:ae:2a" with your device's address.

Next, create a configuration for xboxdrvAUR somewhere, for example:

~/.config/xboxdrv/ipega.conf
#iPEGA PG-9017S Config 

[xboxdrv]
evdev-debug = true
evdev-grab = true
rumble = false
mimic-xpad = true

[evdev-absmap]
ABS_HAT0X = dpad_x
ABS_HAT0Y = dpad_y

ABS_X = X1
ABS_Y = Y1

ABS_Z  = X2
ABS_RZ = Y2

[axismap]
-Y1 = Y1
-Y2 = Y2

[evdev-keymap]
BTN_EAST=a
BTN_C=b
BTN_NORTH=y
BTN_SOUTH=x
BTN_TR2=start
BTN_TL2=back
BTN_Z=rt
BTN_WEST=lt

BTN_MODE = guide

Refer to the xboxdrv man to see all the options.

Now when you have the config and your device is connected you can start the xboxdrvAUR like so:

sudo xboxdrv --evdev /dev/btjoy --config .config/xboxdrv/ipega.conf

Your games will now work with bluetooth gamepad as long as xboxdrv is running.

Steam Controller

The steam package (starting from version 1.0.0.51-1) will recognize the controller and provide keyboard/mouse/gamepad emulation while Steam is running. The in-game Steam overlay needs to be enabled and working in order for gamepad emulation to work. You may need to run udevadm trigger with root privileges or plug the dongle out and in again, if the controller doesn't work immediately after installing and running steam. If all else fails, try restarting the computer while the dongle is plugged in.

If you can't get the Steam Controller to work, see #Steam Controller not pairing.

Alternatively you can install python-steamcontroller-gitAUR to have controller and mouse emulation without Steam or sc-controllerAUR for a versatile graphical configuration tool simillar to what is provided by the steam client.

On some desktop environments the on screen keyboard might freeze when trying to input text after two characters. This is a problem with window focus. Check the settings for your window manager to see if it is possible to have focus follow the mouse or automatically focus new windows.

Note: If you use Steam without its runtime, you might actually need to disable the overlay for the controller to work in certain games (Rocket Wars, Rocket League, Binding of Isaac, etc.). Right click on a game in your library, select "Properties", and uncheck "Enable Steam Overlay".

Wine

python-steamcontroller-gitAUR can also be used to make the Steam Controller work for games running under Wine. You need to find and download the application xbox360cemu.v.3.0 (e.g. from here: https://github.com/jacobmischka/ds4-in-wine/tree/master/xbox360cemu.v.3.0). Then copy the files dinput8.dll, xbox360cemu.ini, xinput1_3.dll and xinput_9_1_0.dll to the directory that contains your game executable. Edit xbox360cemu.ini and only change the following values under [PAD1] to remap the Steam Controller correctly to a XBox Controller.

xbox360cemu.ini
Right Analog X=4
Right Analog Y=-5
A=1
B=2
X=3
Y=4
Back=7
Start=8
Left Thumb=10
Right Thumb=11
Left Trigger=a3
Right Trigger=a6

Now start python-steamcontroller in Xbox360 mode (sc-xbox.py start). You might also want to copy XInputTest.exe from xbox360cemu.v.3.0 to the same directory and run it with Wine in order to test if the mappings work correctly. However neither mouse nor keyboard emulation work with this method.

Alternatively you can use sc-controllerAUR (github) for a similar graphical setup as steams own configurator. As of writing, it's a bit buggy here and there but offers an easy click and go way of configuring the controller.

Xbox 360 controller

Both the wired and wireless (with the Xbox 360 Wireless Receiver for Windows) controllers are supported by the xpad kernel module and should work without additional packages.

It has been reported that the default xpad driver has some issues with a few newer wired and wireless controllers, such as:

If you experience such issues, you can use either #SteamOS xpad or #xboxdrv instead of the default xpad driver.

If you wish to use the controller for controlling the mouse, or mapping buttons to keys, etc. you should use the xf86-input-joystickAUR package (configuration help can be found using man joystick). If the mouse locks itself in a corner, it might help changing the MatchDevicePath in /etc/X11/xorg.conf.d/50-joystick.conf from /dev/input/event* to /dev/input/js*.

Tip: If you use the TLP power management tool, you may experience connection issues with your Microsoft wireless adapter (e.g. the indicator LED will go out after the adapter has been connected for a few seconds, and controller connection attempts fail). This is due to TLP's USB autosuspend functionality, and the solution is to add the Microsoft wireless adapter's device ID to this feature's blacklist (USB_BLACKLIST, check TLP configuration for more details).

SteamOS xpad

If you have issues with the default xpad kernel module, you can install the SteamOS version. There is still a known issue with compatibility between wireless Xbox360 controllers and games made in GameMaker Studio. If you encounter this problem, the only known workaround is to use xboxdrv. YoYo Games has refused to acknowledge this as a bug with their product and it is unlikely to ever be fixed.

First make sure you have DKMS installed and running, then install the modified kernel module steamos-xpad-dkmsAUR. During the installation you'll see that new xpad kernel module is strapped to your current kernel:

Creating symlink /var/lib/dkms/steamos-xpad-dkms/0.1/source ->
                 /usr/src/steamos-xpad-dkms-0.1
 
DKMS: add completed.
 
Kernel preparation unnecessary for this kernel.  Skipping...
 
Building module:
cleaning build area....
make KERNELRELEASE=3.12.8-1-ARCH KVERSION=3.12.8-1-ARCH....
cleaning build area....

Then unload the old xpad module and load new one:

# rmmod xpad
# modprobe steamos-xpad

Or just restart your computer.

xboxdrv

xboxdrv is an alternative to xpad which provides more functionality and might work better with certain controllers. It works in userspace and can be launched as system service.

Install it with the xboxdrvAUR package. Then start/enable xboxdrv.service.

If you have issues with the controller being recognized but not working in steam games or working but with incorrect mappings, it may be required to modify you config as such:

/etc/default/xboxdrv/
[xboxdrv]
silent = true
device-name = "Xbox 360 Wireless Receiver"
mimic-xpad = true
deadzone = 4000

[xboxdrv-daemon]
dbus = disabled

Then restart xboxdrv.service.

Multiple controllers

xboxdrv supports a multitude of controllers, but they need to be set up in /etc/default/xboxdrv. For each extra controller, add an next-controller = true line. For example, when using 4 controllers, add it 3 times:

 [xboxdrv]
 silent = true
 next-controller = true
 next-controller = true
 next-controller = true
 [xboxdrv-daemon]
 dbus = disabled

Then restart xboxdrv.service.

Mimic Xbox 360 controller with other controllers

xboxdrv can be used to make any controller register as an Xbox 360 controller with the --mimic-xpad switch. This may be desirable for games that support Xbox 360 controllers out of the box, but have trouble detecting or working with other gamepads.

First, you need to find out what each button and axis on the controller is called. You can use evtest for this. Run evtest and select the device event ID number (/dev/input/event*) that corresponds to your controller. Press the buttons on the controller and move the axes to read the names of each button and axis.

Here is an example of the output:


Event: time 1380985017.964843, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90003
Event: time 1380985017.964843, type 1 (EV_KEY), code 290 (BTN_THUMB2), value 1
Event: time 1380985017.964843, -------------- SYN_REPORT ------------
Event: time 1380985018.076843, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90003
Event: time 1380985018.076843, type 1 (EV_KEY), code 290 (BTN_THUMB2), value 0
Event: time 1380985018.076843, -------------- SYN_REPORT ------------
Event: time 1380985018.460841, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
Event: time 1380985018.460841, type 1 (EV_KEY), code 289 (BTN_THUMB), value 1
Event: time 1380985018.460841, -------------- SYN_REPORT ------------
Event: time 1380985018.572835, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
Event: time 1380985018.572835, type 1 (EV_KEY), code 289 (BTN_THUMB), value 0
Event: time 1380985018.572835, -------------- SYN_REPORT ------------
Event: time 1380985019.980824, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90006
Event: time 1380985019.980824, type 1 (EV_KEY), code 293 (BTN_PINKIE), value 1
Event: time 1380985019.980824, -------------- SYN_REPORT ------------
Event: time 1380985020.092835, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90006
Event: time 1380985020.092835, type 1 (EV_KEY), code 293 (BTN_PINKIE), value 0
Event: time 1380985020.092835, -------------- SYN_REPORT ------------
Event: time 1380985023.596806, type 3 (EV_ABS), code 3 (ABS_RX), value 18
Event: time 1380985023.596806, -------------- SYN_REPORT ------------
Event: time 1380985023.612811, type 3 (EV_ABS), code 3 (ABS_RX), value 0
Event: time 1380985023.612811, -------------- SYN_REPORT ------------
Event: time 1380985023.708768, type 3 (EV_ABS), code 3 (ABS_RX), value 14
Event: time 1380985023.708768, -------------- SYN_REPORT ------------
Event: time 1380985023.724772, type 3 (EV_ABS), code 3 (ABS_RX), value 128
Event: time 1380985023.724772, -------------- SYN_REPORT ------------

In this case, BTN_THUMB, BTN_THUMB2 and BTN_PINKIE are buttons and ABS_RX is the X axis of the right analogue stick. You can now mimic an Xbox 360 controller with the following command:

$ xboxdrv --evdev /dev/input/event* --evdev-absmap ABS_RX=X2 --evdev-keymap BTN_THUMB2=a,BTN_THUMB=b,BTN_PINKIE=rt --mimic-xpad

The above example is incomplete. It only maps one axis and 3 buttons for demonstration purposes. Use xboxdrv --help-button to see the names of the Xbox controller buttons and axes and bind them accordingly by expanding the command above. Axes mappings should go after --evdev-absmap and button mappings follow --evdev-keymap (comma separated list; no spaces).

By default, xboxdrv outputs all events to the terminal. You can use this to test that the mappings are correct. Append the --silent option to keep it quiet.

Logitech Dual Action

The Logitech Dual Action gamepad has a very similar mapping to the PS2 pad, but some buttons and triggers need to be swapped to mimic the Xbox controller.

 # xboxdrv --evdev /dev/input/event* \
   --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_TRIGGER=x,BTN_TOP=y,BTN_THUMB=a,BTN_THUMB2=b,BTN_BASE3=back,BTN_BASE4=start,BTN_BASE=lt,BTN_BASE2=rt,BTN_TOP2=lb,BTN_PINKIE=rb,BTN_BASE5=tl,BTN_BASE6=tr \
   --mimic-xpad --silent
PlayStation 2 controller via USB adapter

To fix the button mapping of PS2 dual adapters and mimic the Xbox controller you can run the following command:

 # xboxdrv --evdev /dev/input/event* \
   --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
PlayStation 3 controller via USB

If you own a PS3 controller and can connect with USB, xboxdrv has the mappings built in. Just run the program (and detach the running driver) and it works!

# xboxdrv --silent --detach-kernel-driver

There are some games which might also need the --mimic-xpad option, additionally.

PlayStation 3 controller via Bluetooth

With your controller connected via Bluetooth, find the device address with bluetoothctl. Then create a new udev rule with the following content:

/etc/udev/rules.d/99-dualshock.rules
KERNEL=="event*", SUBSYSTEM=="input", ATTRS{uniq}=="<device_addr_you_got_on_pairing>", SYMLINK+="input/dualshock3"

The address must be in lowercase, like 06:9a:b4:c8:ef:8b.

Now run xboxdrv over the new device:

$ xboxdrv --evdev /dev/input/dualshock3 --mimic-xpad
PlayStation 4 controller

To fix the button mapping of PS4 controller you can use the following command with xboxdrv (or try with the ds4drv program):

 # xboxdrv \
   --evdev /dev/input/by-id/usb-Sony_Computer_Entertainment_Wireless_Controller-event-joystick\
   --evdev-absmap ABS_X=x1,ABS_Y=y1                 \
   --evdev-absmap ABS_Z=x2,ABS_RZ=y2                \
   --evdev-absmap ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \
   --evdev-keymap BTN_A=x,BTN_B=a                   \
   --evdev-keymap BTN_C=b,BTN_X=y                   \
   --evdev-keymap BTN_Y=lb,BTN_Z=rb                 \
   --evdev-keymap BTN_TL=lt,BTN_TR=rt               \
   --evdev-keymap BTN_SELECT=tl,BTN_START=tr        \
   --evdev-keymap BTN_TL2=back,BTN_TR2=start        \
   --evdev-keymap BTN_MODE=guide                    \
   --axismap -y1=y1,-y2=y2                          \
   --mimic-xpad                                     \
   --silent

Troubleshooting

Joystick moving mouse

Sometimes USB joystick can be recognized as HID mouse (only in X, it is still being installed as /dev/input/js0 as well). Known issue is cursor being moved by the joystick, or escaping to en edge of a screen right after plugin. If your application can detect joystick by it self, you can remove the xf86-input-joystickAUR package.

A more gentle solution is described in #Disable joystick from controlling mouse.

Joystick not working in FNA/SDL based games

If you are using a generic non-widely used gamepad you may encounter issues getting the gamepad recognized in games based on SDL. Since 14 May 2015, FNA supports dropping a gamecontrollerdb.txt into the executable folder of the game, for example the SDL_GameControllerDB.

As an alternative and for older versions of FNA or for SDL you can generate a mapping yourself by downloading the SDL source code via http://libsdl.org/, navigating to /test/, compile the controllermap.c program (alternatively install controllermapAUR) and run the test. After completing the controllermap test, a guid will be generated that you can put in the SDL_GAMECONTROLLERCONFIG environment variable which will then be picked up by SDL/FNA games. For example:

 $ export SDL_GAMECONTROLLERCONFIG="030000008f0e00000300000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,"

Joystick not recognized by all programs

Some software, Steam for example, will only recognize the first joystick it encounters. Due to a bug in the driver for Microsoft wireless periphery devices this can in fact be the bluetooth dongle. If you find you have a /dev/input/js* and /dev/input/event* belonging to you keyboard's bluetooth transceiver you can get automatically get rid of it by creating according udev rules. Create a /:

/etc/udev/rules.d/99-btcleanup.rules
ACTION=="add", KERNEL=="js[0-9]*", SUBSYSTEM=="input", KERNELS=="...", ATTRS{bInterfaceSubClass}=="00", ATTRS{bInterfaceProtocol}=="00", ATTRS{bInterfaceNumber}=="02", RUN+="/usr/bin/rm /dev/input/js%n"
ACTION=="add", KERNEL=="event*", SUBSYSTEM=="input", KERNELS=="...", ATTRS{bInterfaceSubClass}=="00", ATTRS{bInterfaceProtocol}=="00", ATTRS{bInterfaceNumber}=="02", RUN+="/usr/bin/rm /dev/input/event%n"

Correct the KERNELS=="..." to match your device. The correct value can be found by running

# udevadm info -an /dev/input/js0

Assuming the device in question is /dev/input/js0. After you placed the rule reload the rules with

# udevadm control --reload

Then replug the device making you trouble. The joystick and event devices should be gone, although their number will still be reserved. But the files are out of the way.

Steam Controller not pairing

There are some unknown cases where the packaged udev rule for the Steam controller does not work (FS#47330). The most reliable workaround is to make the controller world readable. Copy the rule /usr/lib/udev/rules.d/80-steam-controller-permission.rule to /etc/udev/rules.d and set MODE="0666" e.g.

/etc/udev/rules.d/80-steam-controller-permission.rule
#USB devices
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666", TAG+="uaccess"
KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"

If you want your system to recognize the Steam controller after hot-swapping wireless/wired connections or when connected via micro-USB cable with the dongle plugged in, you may need a more complicated udev rule. Otherwise, the controller might stop working or behave like a mouse and keyboard after hot-swapping. The following rule was suggested by a Valve developer [1] which is also included in the package steam-devices

/etc/udev/rules.d/99-steam-controller-perms.rules
# This rule is needed for basic functionality of the controller in Steam and keyboard/mouse emulation
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"

# This rule is necessary for gamepad emulation
KERNEL=="uinput", MODE="0660", GROUP="steamcontroller", OPTIONS+="static_node=uinput"

# DualShock 4 wired
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE="0666"
# DualShock 4 wireless adapter
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ba0", MODE="0666"
# DualShock 4 slim wired
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", MODE="0666"

# Valve HID devices over USB hidraw
KERNEL=="hidraw*", ATTRS{idVendor}=="28de", MODE="0666"

# Valve HID devices over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*28DE:*", MODE="0666"

# DualShock 4 over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*054C:05C4*", MODE="0666"

# DualShock 4 Slim over bluetooth hidraw
KERNEL=="hidraw*", KERNELS=="*054C:09CC*", MODE="0666" 

Create a group of steam controller users.

# groupadd steamcontroller

And add your user to that group.

# gpasswd -a $USER steamcontroller