Homepage › Forums › RetroPie Project › Controller Configuration in RetroPie › Capture gamepad as keyboard in Linux shell
- This topic has 7 replies, 3 voices, and was last updated 8 years, 10 months ago by labelwhore.
-
AuthorPosts
-
02/01/2016 at 22:15 #115946targetboyParticipant
I need to figure out how to capture a game pad input as a keyboard key when Emulation Station has called out to the Linux shell.
My goal is to have an image slideshow play when I am not playing games on my emulator. I created the file slideshow.sh under /home/pi/RetroPie/roms/pc, with the following contents:
#!/bin/bash
fbi /home/slideshow/*.jpg -a -noverbose -u -t 120This works great as a slideshow. I put images in /home/slideshow and they display at 2 minute intervals. However, I have to press ESC to return to Emulation Station. I would like to add a line to read a button on the game pad as ESC. When I finish this project, it will not have a keyboard attached, so I need to be able to get out of the slideshow with a button press.
Google searches found a bunch of programs dealing with converting game pad inputs to keyboard inputs, but none are pre-installed on RetroPie.
Is there something already installed that I can activate with a command in the script above?
02/01/2016 at 22:26 #115951labelwhoreParticipantThat depends… what type of controller? I know how to do it with an xbox360 controller, but not others.
02/01/2016 at 22:53 #115958targetboyParticipantIt is a generic USB gamepad styled after Nintendo 64 (I think). It has a D-pad, Buttons labeled A, B, X and Y and two shoulder buttons. Whatever works for the X-box controller should work for it as well. It si at least something to try.
02/01/2016 at 23:32 #115962petrockblogKeymasteryou can use xboxdrv on any event device to map joystick to keypresses, so that should work.
02/01/2016 at 23:42 #115963labelwhoreParticipantWith xboxdrv, you need to start it with some commandline options like
--ui-button-map GUIDE=KEY_ESC
or something to that effect. This would map the xbox button to the escape key. It works for the other buttons too. I’d double check the syntax in the manual though, as I’ve only ever done this with config files and the –alt-config tag.02/02/2016 at 04:10 #115996targetboyParticipantNo luck. xboxdrv did not see the gamepad. I have been trying to use joy2key, but that does not seem to be what I need either. I used this command with joy2key:
joy2key -terminal -axis 0 0 0 0 -thresh 0 0 0 0 -buttons q q q q q q q q
The result was a cursor after the joy2key startup text. I could press buttons and it would display “q”, so it is reading the joystick. The thing is, it does not start the slideshow until I press Ctrl-C to break out, at which point it is not reading the stick any more.
Is there some way I could start it in a different process, and end that process before exiting the script?
Sorry to be so ignorant. I am not very experienced with Linux.
02/02/2016 at 05:25 #116001targetboyParticipantI figured it out. Here is the final script:
#!/bin/bash
joy2key -terminal -axis 0 0 0 0 -thresh 0 0 0 0 -buttons q q q q q q q q &
fbi /home/slideshow/*.jpg -a -noverbose -u -t 120
pkill joy2keyThe joy2key command starts reading the joystick with all buttons returning “q”. The “&” at the end makes it start in the background.
The pkill statement kills the joy2kill process, that otherwise hung around throwing keys into the standard output and generally being a nuisance.
02/02/2016 at 15:14 #116034labelwhoreParticipantI was gonna say, try running it in the background, but it looks like that’s exactly what you did. :)
-
AuthorPosts
- The forum ‘Controller Configuration in RetroPie’ is closed to new topics and replies.