HI there
I´ve recently entered the ubuntu world with my PS3. This is a post I stuck on the PSubuntu forums, but thought I would mirror it here are people are having problems figuring out how to use joy2key
If like me, you hate the way some emulators allow/don´t allow joystick control then this is the post for you !
This is especially relevant if you use a sixaxis joypad. With the sixaxis, the d-pad is recognised as buttons and button0 = the select key ! This is no good for programs that will look at the first 2 axis in you dev/input/js0 and use them for up/down/left/right. Besides, with the amiga, the platformers tended to have up as jump, no good with the sixaxis stick.
eg VICE - c64 emulator, is quite good, left stick for movement, any button (0 through to 19) it will accept as the fire button. UAE however, will only accept button0 as fire, so you have to use left stick and select button as fire button. Unacceptable !
Code:
sudo apt-get install joy2key
then
Code:
joy2key -dev /dev/input/js0 -terminal
It will prompt you
Code:
Calibrating axis 0
Please center the axis and press a button.
?
So just push any button on the pad without touching the stick. It will change to
Code:
Locked at 0
Please move the axis to its lowest position and press a button.
?
Hold the left stick to the left, it will change to
now hit any button. It will then change to
Code:
Please move the axis to its highest position and press a button.
value: 0
do what it says....it will change to
It will then tell you
Code:
Using deadzone of 50%
Calibrations set at:
Axis 0 low threshold set at -16383
Axis 0 high threshold set at 16383
(you can put these in your .joy2keyrc to avoid calibrating in the future)
So repeat for axis 1 (up/down on left stick) if you please, but it will tell you the same thing as me so you can do it or just hammer the X button until you reach axis 26 and it give you the ctrl-c to exit prompt.
We are going to keep this info in a config file so u dont have to do it every time.
will open a blank file, paste the following in
Code:
COMMON
-X
-dev /dev/input/js0
-thresh -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383
16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383
16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383
ctrl-X to exit, then Y for yes to save.
Thats the basic config file sorted ! Now for the fun bit. Getting joy2key to map a keystroke to the joypad movements.
there are 2 options
-buttons
-axis
now say for instance i had
Code:
-buttons a b c d e f g h i
This would tell joy2key that when i push button0 - send a signal saying a has just been pressed. When i push button1 - send a signal saying b has just been pressed etc
also
would tell it that if axis0 minimum (ie left) is pushed, send the a keystroke and if axis0 maximum (ie right) is pushed, send the d keystroke. If axis 1 minimum (ie up) is pushed then send the w keystroke etc etc
for keys like left control right shift etc, you need the key mappings that X11 uses. there is an app that will tell you that ! ie for UAE, i want the fire button to be right control so i need to know what right control is as a keymap in Xwindows
will open the even viewer and will display a lot of junk
Code:
PropertyNotify event, serial 18, synthetic NO, window 0x3400001,
atom 0x107 (XKLAVIER_STATE), time 4250290198, state PropertyNewValue
PropertyNotify event, serial 26, synthetic NO, window 0x3400001,
atom 0x12b (_NET_WM_ICON_GEOMETRY), time 4250290327, state PropertyNewValue
FocusOut event, serial 27, synthetic NO, window 0x3400001,
mode NotifyNormal, detail NotifyNonlinear
just press the key u want to know the keymap for ie right control and it shows
Code:
KeyRelease event, serial 30, synthetic NO, window 0x3400001,
root 0x3f, subw 0x0, time 4250341503, (805,386), root:(810,435),
state 0x4, keycode 109 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
and there is our keymap in the middle Control_R. Use this to find out what any key maps to for use in the config file.
Now, I want to map up/down/left/right on the keyboard to d-pad up/down/left/right. I also want to map right control to the X button. Using the event viewer as described above I find that they are conveniently called Up Down Left Right and Control_R
Last piece in the puzzle is knowing what the buttons all are. If you have jscalibrator, it will show you what the buttons are by trial and error pressing and seeing what button depresses in the window.
Or you could just look at the list below! (for the SIXAXIS pad)
button0 Select
button1 L3
button2 R3
button3 Start
button4 Dpad Up
button5 Dpad Right
button6 Dpad Down
button7 Dpad Left
button8 L2
button9 R2
button10 L1
button11 R1
button12 Triangle
button13 Circle
button14 Cross
button15 Square
button16 PS Button
pain in the neck thing is, you cant tell joy2key to map buttons 4, 5, 6, 7 and 14. Since it runs from the command line it needs something for all the buttons up to the last one you are using.
so our code is
Code:
-buttons r r r r Up Right Down Left r r r r r r Control_R
as you can see, i just mapped r to every button from 0 upwards apart from the one i wanted, starting from button0 !
so from that button 4 is Up on the keyboard (from the arrow keys), button5 is Right, button6 is down & button 7 is left - all from the arrow keys. Lastly button 14 is right control.
So we have now mapped up/down/left/right on the D-pad to the arrow keys and the X button to right control!
as a last measure, we will map the left stick to up down left right as well
Code:
-axis Left Right Up Down
remember the order is -axis axis0min axis0max axis1min axis1max
So lets throw all that in the config file (~/.joy2keyrc). We will put it in a section called uae (as the config lets you have lots of configs for different apps)
Code:
COMMON
-X
-dev /dev/input/js0
-thresh -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383
16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383
16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383 -16383 16383
-16383 16383
START uae
-X
-buttons r r r r Up Right Down Left r r r r r r Control_R
-axis Left Right Up Down
you get the format dont you?
i could equally put in more configs for different apps by just starting them save you .joy2keyrc file and you are ready to start
open 2 terminal windows
in one start your app (eg VICE or UAE). So we now have our emu running.
in the 2nd window type
Code:
joy2keyrc -config uae
and it will say
Code:
naivri@localhost:~$ joy2key -config uae
joy2key - reads joystick status and dispatches keyboard events
By Peter Amstutz (tetron@interreality.org)
This is free software under the GNU General Public License (GPL v2)
(see COPYING in the joy2key archive)
You are welcome to use/modify this code, and please e-mail me
if anything cool comes of it!
Version: 1.6.1 Binary built on Jan 26 2007 at 17:31:47
Please select a window to send events to
your mouse pointer will change to a cross and just click the window that has your emulator running. It will then change to
Code:
Initialization complete, entering main loop, ^C to exit...
Play away till your heart is content !
Its quite clever, when you close the window of the app/emu you are playing, joy2key will detect it and kill its self!
Any questions, let me know
Bookmarks