A couple of months ago I stumbled upon a slew of information related to using the PS3 controller as a joystick on Linux. I immediately took my PS3 controller and started experimenting with the documentation out there for doing this sort of thing. Unfortunately however, not everything mentioned in this documentation worked correctly. For instance, I was not able to use a joystick on the controller to control the mouse without a separate piece of middleware. This was because the application I used (the only decent one I was able to find) to signal key presses for every button press on the controller, is unmaintained and had a blocker bug with mouse emulation.
You will need two components in order to make this work: the first being QJoyPad to bind controller buttons to keys, and JoyMouse to use one of the joysticks on the controller to control the mouse. Also remember that I am only using the USB cable to use the controller rather than using it via Bluetooth. I will post directions for using Bluetooth and the accelerometers in the controller at a later date, if I am able to get a hold of a Bluetooth adapter. Nevertheless, the tools are the same.
Because QJoyPad is currently unmaintained, and the packages available from their site are out of date; we will need to compile from source. The first thing we need to do is install dependencies:
sudo apt-get install libqt3-mt-dev libxtst-dev
Then download the tarball from here, extract it, and compile as usual.
cd ~/Desktop/qjoypad-3.4.1/src make sudo make install
Before we can get started with QJoyPad; we need to first plug in the controller and make sure that it’s being recognized by Linux. First make sure that your PlayStation 3 is completely turned off (via the switch in the back). Then plug the one end of the USB cable into the computer, but leave it unplugged from the controller. Hit the PS button to activate the controller and the red LED’s on the top will start to blink. Now plug the USB cable into the controller and verify that it has been recognized.
maddog39@desktop:~$ ls -a /dev/input | grep js js0
Though take note to the device name of the controller (/dev/input/js0 in my case) as we will need to use this later. Now we can start to configure the buttons on the controller and assign them to keyboard keystrokes. When you launch QJoyPad (via the qjoypad command as no Applications menu item is provided), click on it’s tray icon and the button editor will appear.
The first thing you will want to do is create a new layout. Simply click Add at the top of the window and enter a label for your layout. You can see which controller buttons correspond to buttons in QJoyPad by pressing or holding the button you want to modify as it will appear highlighted in blue when its activated. To assign a keypress to any button or axis, click the button or axis you want to modify and a dialog will appear, then click [NO KEY] and hit the key you want to assign.
In order to be able to use either of the PS3 controller’s joysticks as mice, we need to install JoyMouse which can be downloaded here. Its a really simple program and as far as I know it doesnt have any dependencies so you should be good with a standard build. Extract the tarball to your desktop and open a terminal in the JoyMouse directory.
cd ~/Desktop/joymouse-0.5 ./configure make sudo make install
Once JoyMouse is installed, we need to modify our xorg.conf to add a new pointer device.
sudo nano /etc/X11/xorg.conf
Now go to the end of the file and you will want to insert the following lines.
Section "InputDevice" Identifier "Joystick" Driver "mouse" Option "Protocol" "ExplorerPS/2" Option "Device" "/dev/joymouse" Option "SendCoreEvents" "true" Option "ZAxisMapping" "4 5 6 7" EndSection
Then go back up to the “ServerLayout” section of the file and in that section under your mouse input device, insert the following line.
When your finished, Ctrl+O, Enter, then Ctrl+X to save and exit. Now heres the thing; in order for this to work we need to create a pipe using the mkfifo command, but it needs to always be there for JoyMouse to work. The problem is that these pipes are not retained over reboots: meaning that you have to recreate them everytime you want to use JoyMouse. I have also read that if the pip does not exist, it may cause Xorg to fail to start. I have yet to find a good solution to this problem, but for now manual will have to do.
sudo mkfifo -m 0777 /dev/joymouse
Running the JoyMouse program is fairly simple, just keep in mind that when you assign axes, they are always in order. So for example, if you wanted to use the right joystick as your mouse you would use the following.
joymouse -M - -M - -M x -M y
We ignored (using a dash) the first two axes as those are left/right and up/down for the left joystick and assigned X and Y to the left/right and up/down on the right joystick respectively. However, if you wanted to use the left joystick as the mouse, the command would read like this.
joymouse -M x -M y
If you would like, you could add this joymouse command to your GNOME (or whatever desktop environment you prefer) startup programs. In GNOME this would be: System > Preferences > Sessions > Startup Programs. But as mentioned earlier, remember that you need the /dev/joymouse pipe to exist first. After that, your done. Test out the controller with several different games and or applications and tweak the settings to your liking.Filed under:
Tags: configure, controller, Linux, playstation, ps3