| PSUbuntu Forums http://psubuntu.com/forums/ |
|
| HOWTO: SIXAXIS as mouse (+more) in an X env http://psubuntu.com/forums/viewtopic.php?f=4&t=5 |
Page 1 of 4 |
| Author: | xat [ Wed Mar 26, 2008 9:54 pm ] |
| Post subject: | HOWTO: SIXAXIS as mouse (+more) in an X env |
Preface The sixaxis is considered an input device by Linux; more specifically, it's regarded as a joystick. X provides the proper interfaces necessary to use several kinds of input devices including joysticks. What this means for us is that we can tell X to give the sixaxis mouse (and keyboard) functionality without 3rd party programs such as joy2key or js2mouse. This should work with either a usb or bluetooth (http://psubuntu.com/forum/viewtopic.php?t=2408) sixaxis. Package(s) necessary: -xserver-xorg-input-joystick Steps: 1. Install the xserver-xorg-input-joystick package (on Debian variants such as Ubuntu: sudo apt-get install xserver-xorg-input-joystick) 2. Open your xorg.conf for modification (sudo nano -w /etc/X11/xorg.conf). 3. Add the following new "InputDevice" section (I added mine after my mouse's inputdevice section). This section is standalone so it can technically go anywhere in your xorg.conf: Code: Section "InputDevice" *Your Option "Device" line may vary depending on the /dev/input/js<n> device your sixaxis is assigned to. A safer setting would probably be /dev/input/by-id/usb-Sony_Bluetooth_Transceiver-joystickDriver "joystick" Identifier "SIXAXIS" Option "Device" "/dev/input/js0" Option "Buttons" "19" #15 - x Option "MapButton15" "button=3" #16 - square Option "MapButton16" "button=1" Option "MapAxis1" "mode=relative axis=1.0x deadzone=0" Option "MapAxis2" "mode=relative axis=1.0y deadzone=0" EndSection 4. Scroll to the "ServerLayout" section and add the following entry (again I added this entry after my mouse entry): Code: InputDevice "SIXAXIS" "SendCoreEvents" Your "ServerLayout" section will look something like:Code: Section "ServerLayout" Identifier "Default Layout" Screen "Default Screen" InputDevice "Generic Keyboard" InputDevice "Configured Mouse" InputDevice "SIXAXIS" "SendCoreEvents" EndSection 5. Enable your sixaxis (press the PS button) if you haven't already. 6. Restart X (ctrl+alt+backspace) Test your left analog stick to see if you have cursor movement. If you do, then you're all set. Square is left click, and X is right click. Notes: -You can modify the axis sensitivities and deadzones by altering the lines that apply to MapAxis1 and MapAxis2. The coefficients are sensitivity multipliers. The deadzone range is anywhere from 0-30000 (default 1000 - I set mine to 0). -For more information, man joystick after you have installed the xserver-xorg-input-joystick package. Advanced usage: The xserver-xorg-input-joystick package also allows keystrokes to be bound to any button. From man joystick: Code: GENERATING KEY EVENTS With this knowledge, we can map keystrokes intuitively to specific buttons. All mappings go within the "InputDevice" section you added for your sixaxis. For example:Proving a "key=<keycode>[,<keycode>[...]]" option will generate X Events with the specified keycodes in order, when the joystick button is pressed. When the button is released, the keys are released in the reverse order. To lookup keycodes for KeySyms, you can use xmodmap -pk. You can use unused keycodes and map them to a KeySym of your choice using xmodmap(1). You can specify up to 4 keycodes per joystick button. Examples: Option "MapButton1" "key=64,23" will generate Alt_L+Tab when the button is pressed. Code: Section "InputDevice" 64=Left Alt, 100=Left arrow, 102=right arrow. For a more comprehensive listing of keyboard mappings either use xmodmap -pk or check http://tldp.org/HOWTO/Intkeyb/x772.html.Driver "joystick" Identifier "SIXAXIS" Option "Device" "/dev/input/js0" Option "Buttons" "18" # Say you want to add back / forward functionality to your R1 and L1 buttons so you can use them in Firefox. # The shortcut for back and forward in Firefox is alt+left arrow and alt+right arrow #11 - L1 Option "MapButton11" "key=64,100" #12 - R1 Option "MapButton12" "key=64,102 #15 - x Option "MapButton15" "button=2" #16 - square Option "MapButton16" "button=1" Option "MapAxis1" "mode=relative axis=1.0x deadzone=0" Option "MapAxis2" "mode=relative axis=1.0y deadzone=0" EndSection If you wish to make your own mappings, I have documented some of the buttons: #5 - d-pad up #6 - d-pad right #7 - d-pad down #8 - d-pad left #11 - L1 #12 - R1 #13 - triangle #14 - circle #15 - x #16 - square Nearly all buttons are pressure sensitive, and as such have their own axis. To map to a specific axis take the button number and add 4. For example, the pressure sensitive axis to L1 is Axis15 (L1 is button 11 therefore 11+4=15). |
|
| Author: | x4nd1 [ Fri Mar 28, 2008 6:43 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
Thanks! A very good tutorial. It works well for me with usb and bluetooth! FYI: I am using the 2.6.24 Kernel from CELL-Linux-CL_20080201 I have some questions: 1) Shouldn't it be Option "Buttons" "19" instead of 18? The MapButton goes from "MapButton1" up to "MapButton19" afaik. 2) After pressing the PS Button, my Xserver does not automatically recognize that the joystick input device is present. But after using jstest (see cmd line below), it recognizes it and I can use the controller as an xserver input device. Code: jstest /dev/input/by-id/usb-Sony_Bluetooth_Transceiver-joystick Do you have any ideas how to make it "hotplug-able" or does it work for you?3) Sometimes it happens that the key event generating gets crazy and generates lots of random keycodes on my PS3. Did anyone encounter the same problem? Regards, x4 |
|
| Author: | xat [ Fri Mar 28, 2008 7:27 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
x4nd1 wrote: 1) Shouldn't it be Option "Buttons" "19" instead of 18? The MapButton goes from "MapButton1" up to "MapButton19" afaik. Yeah. I was finding out the button assignments through jstest and hastily noted the count to be 18, forgetting that jstest starts at 0. Thanks, fixed. Quote: 2) After pressing the PS Button, my Xserver does not automatically recognize that the joystick input device is present. But after using jstest (see cmd line below), it recognizes it and I can use the controller as an xserver input device. Code: jstest /dev/input/by-id/usb-Sony_Bluetooth_Transceiver-joystick Do you have any ideas how to make it "hotplug-able" or does it work for you?I'm guessing the device drivers aren't loaded if the sixaxis isn't initially detected. Does this occur when you hook it up via usb? Quote: 3) Sometimes it happens that the key event generating gets crazy and generates lots of random keycodes on my PS3. Did anyone encounter the same problem? I get this as well. Haven't figured out what it is yet (I should probably have made a disclaimer for it), but for now I'm using it strictly for mouse functionality. One thing to try is assigning keys to the button axes instead of the buttons themselves. I haven't tried it yet but it couldn't hurt. For instance I tried up/right/down/left arrow keys to assigned to the appropriate d-pad button, but holding these buttons while in a terminal would sometimes yield actual letters (A/B/C/D). It's weird since jstest shows that the buttons have simple on/off states, so they really shouldn't be going haywire. |
|
| Author: | x4nd1 [ Fri Mar 28, 2008 8:27 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
Quote: Yeah. I was finding out the button assignments through jstest and hastily noted the count to be 18, forgetting that jstest starts at 0. Thanks, fixed. Yep that one tricked me too :DBTW: The middle mouse button is "button=2" and the right mouse button is "button=3" in xorg. Quote: I'm guessing the device drivers aren't loaded if the sixaxis isn't initially detected. Does this occur when you hook it up via usb? Yes. With USB it also does not detect it automatically. I need to have it plugged in before xserver starts.With bluetooth i need to have it paired before xserver starts. Otherwise I have to start jstest - then it's detected. Quote: One thing to try is assigning keys to the button axes instead of the buttons themselves. I haven't tried it yet but it couldn't hurt. I tried it with the Up key axis (#5+4=9) with: Code: Option "MapAxis9" "key=98" It looks fishy and it didn't work at all...Quote: For instance I tried up/right/down/left arrow keys to assigned to the appropriate d-pad button, but holding these buttons while in a terminal would sometimes yield actual letters (A/B/C/D). It's weird since jstest shows that the buttons have simple on/off states, so they really shouldn't be going haywire. I'm also getting the ABCD errors. The error happens both with USB and with Bluetooth. |
|
| Author: | xat [ Fri Mar 28, 2008 10:46 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
x4nd1 wrote: BTW: The middle mouse button is "button=2" and the right mouse button is "button=3" in xorg. Thanks, fixed. Quote: With USB it also does not detect it automatically. I need to have it plugged in before xserver starts. With bluetooth i need to have it paired before xserver starts. Otherwise I have to start jstest - then it's detected. This might just be the way x works. Might be possible to force load or auto load the driver through a script on start up, but I haven't looked into this too much as my ps3 is rarely fully restarted/shutdown. Quote: I tried it with the Up key axis (#5+4=9) with: Code: Option "MapAxis9" "key=98" It looks fishy and it didn't work at all...Yeah. The man pages don't suggest that it's possible at all, now that I look at it. No idea about the odd keystroke behavior. jstest doesn't seem to suggest that there is any additional behavior beyond on/off... |
|
| Author: | Pajn [ Sat Mar 29, 2008 3:15 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
x4nd1 wrote: Quote: For instance I tried up/right/down/left arrow keys to assigned to the appropriate d-pad button, but holding these buttons while in a terminal would sometimes yield actual letters (A/B/C/D). It's weird since jstest shows that the buttons have simple on/off states, so they really shouldn't be going haywire. I'm also getting the ABCD errors. The error happens both with USB and with Bluetooth. Thats because the terminal is made like that, even if you use a keyboard on pc whit linux that can happen sometimes. _______________________________________ Sorry for bad English, i hope you understand anyway. |
|
| Author: | MattHenley [ Mon Mar 31, 2008 11:37 am ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
xat wrote: For instance I tried up/right/down/left arrow keys to assigned to the appropriate d-pad button, but holding these buttons while in a terminal would sometimes yield actual letters (A/B/C/D). It's weird since jstest shows that the buttons have simple on/off states, so they really shouldn't be going haywire. I'm just about to follow this guide, before I do I thought I would inform you that if you hold shift and press the cursor keys on a keyboard in a terminal window, it outputs ABCD also. Might be of some help in tracking whats happening |
|
| Author: | MattHenley [ Mon Mar 31, 2008 1:12 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
OK, Sweet, I got it working no problem at all with both USB and Bluetooth, thank you so much for your guide. I hav'nt read the advance part just yet but ill probably just map the start button the the return key and the right analouge stick for page up and down. All I need now is an onscreen keyboards and I can sit back and relax |
|
| Author: | xat [ Mon Mar 31, 2008 8:15 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
Hm that actually may be a good hint Matt. I did have a few Shift binds to other buttons - by chance it might be possible that those buttons are locking for whatever reason, but I'm trying to get other things to work right now so I'll work on this later. As noted before, mapping axes to keys doesn't seem to work (and there is nothing that suggests that it should). Regarding an onscreen keyboard: I used to have Triangle bound to alt+shift+K. My keyboard shortcuts define that keystroke combination to run the command "onboard." Onboard is pretty much what you're looking for: an onscreen keyboard. I had circle bound to a keystroke that basically killed onboard when I was done with it. If you're on Ubuntu your distro should already come with onboard so give it a look. |
|
| Author: | Ribs [ Tue Apr 01, 2008 4:49 pm ] |
| Post subject: | Re: HOWTO: SIXAXIS as mouse (+more) in an X env |
A very nice tutorial, thank you. I made some small changes to my button config: Code: Option "MapButton15" "button=1" Option "MapButton13" "button=2" Option "MapButton14" "button=3" This made X the 'left click', O the 'right click', and Triangle the 'middle click'. This feels more natural, given how the controller works in the GameOS. And is how I would reccommend 'normal' users to set it up. However, things get complicated if you're going to use this alongside MythTV. My set-up uses X as the select button in entries, but XOrg will also use X as a left click. MythTV will respond to both the left click and the X in it's own config. You can't see the mouse pointer when MythTV is running, but it will still respond to any button the mouse is under, so you can end up accidentally selecting menu items you didn't mean to. Also, whilst MythTV is running, and you fire up games from it (in this example, ScummVM games which require mouse input), it will still react to you pressing X, and will keep spawning the game every time you left click! There is a simple solution. You can write a script which will 'tie up' mythtv until the game exists, then it will ignore joystick input, which fixes the re-spawning of games, but not the other issue. Or you can use the shoulder pads instead (L1 and R1): Code: Option "MapButton11" "button=1" Option "MapButton12" "button=2" My MythTV set-up sees these buttons as Z and Q, for commercial skipping, and will only react to them whilst watching TV. Much better. My MythTV joystick config is here: http://riblet.homelinux.org/joystickmenurc |
|
| Page 1 of 4 | All times are UTC |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|