Exiting the PCSX2 emulator with gamepad buttons combo instead of keyboard 'ESC' key
-
@daragon to exit a game in any emulator you can use your hotkey button plus start button.
-
@the-doctor unfortunatelly not in PCSX2 :)
EDIT:
So, I figure it out on my own. There were few syntactic errors and the scripts needed to be tweak little bit, but it is working now and I finally can quit PCSX2 with gamepad button combination. Thank you @ringnutz . -
hello i,am stuck at the same piece you where could you please help me with the syntactic errors you mentioned?
from: can't read /var/mail/evdev
./gamepad_wrapper.py: line 2: import: command not found
from: can't read /var/mail/subprocess
./gamepad_wrapper.py: line 8: syntax error near unexpected token(' ./gamepad_wrapper.py: line 8:
gamepad = InputDevice('/dev/input/event15')'my error looks similar to yours i know the right device number is 15 and the button numbers but it won,t work any help would be appreciated
-
At one point i came across the same question of how to convienetly exit non retroarch emulators.
I found this program called antimicro where you can create controller configs. So i made a profile that lets you execeute ALT + F4 when you press "Select" and "Start"
In my runcommand-onstart.sh i have it setup like this:
case $system in "ps2") ## Launch antimicro in the background with a specific profile, which allows us to exit the emulator via standart button combination select + start ## Just like retroarch allows us to antimicro --tray --profile /opt/retropie/configs/all/antimicro_configs/xinput-altf4.gamecontroller.amgp & ;; esac
It basically starts up the antimicro when the system is ps2 and puts it in background.
My runcommand-onend.sh looks like this:
### Only kill antimicro if it is actually running if [[ $(pgrep -c antimicro) > 0 ]] then kill $(pgrep antimicro) fi ##############
Content of my antimicro configfile:
<?xml version="1.0" encoding="UTF-8"?> <gamecontroller configversion="19" appversion="2.23"> <!--The SDL name for a joystick is included for informational purposes only.--> <sdlname>XInput Controller</sdlname> <!--The GUID for a joystick is included for informational purposes only.--> <guid>030000005e0400008e02000010010000</guid> <names/> <sets> <set index="1"> <trigger index="1"> <throttle>positivehalf</throttle> </trigger> <trigger index="2"> <throttle>positivehalf</throttle> </trigger> <button index="5"> <setselect>2</setselect> <setselectcondition>while-held</setselectcondition> </button> </set> <set index="2"> <trigger index="1"> <throttle>positivehalf</throttle> </trigger> <trigger index="2"> <throttle>positivehalf</throttle> </trigger> <button index="5"> <setselect>1</setselect> <setselectcondition>while-held</setselectcondition> <slots> <slot> <code>0x1000023</code> <mode>keyboard</mode> </slot> </slots> </button> <button index="7"> <slots> <slot> <code>0x1000033</code> <mode>keyboard</mode> </slot> </slots> </button> </set> </sets> </gamecontroller>
You might have to fiddle around with the profile since this is made to work with XboxDrv. This has worked quite well for me. Since im running Retropie on a x86 build i dont know if antimicro is available on rasperypie OS
-
Thanks alot for your super quick reply! i,am also running a x86 system i,am using retropie on ubuntu.
I have installed antimicro and i have started it so i have the info like the guid and name of the controller and put them into the antimicro configfile.
But it still won,t work
what is did was re-use the old runcommand-onend and onstart scripts and input you script. Then i changed the directory in the runcommand-onstart.sh to the directory of the antimicro configfile.
and i renamed the gamepad_wrapper.sh to gamepad_wrapper.amgp.any idea what is going wrong here?
ps. when i start the script using the command in the onstart file by hand then it works! somehow it does not start with the emulator i think?
**p.s.s. i found this in the runcommand.log so it works but there is an error
/opt/retropie/configs/all/runcommand-onstart.sh: line 7: syntax error near unexpected token
newline' /opt/retropie/configs/all/runcommand-onstart.sh: line 7:
easc'do you know if the script you posted is complete?**
i think easc should be esac? but then the error is gone fron runcommand.log but then it still does not work!
-
@copywizard2
you are correct!
Since my runcomand script "switch case" statement includes much more entries i simply cut off and made a typo.easc must be esac -> "case" backwards :)
Edit:
In my onstart script i assign another variable:
# get the system name system=$1
You either have to add that to you onstart script or just use $1 in the switch case statement like so:
case $1 in
-
Thanks alot your amazing! it worked with the $1 replacing the $system!
-
So sorry that I was not able to reply to you sooner, I can see that you've got another solution to do that.
The solution through two cycles is not the best in my opinion, but it works. I am not sure if this is universal solution (I doubt), but I made a clean RetroPie install a week ago, paste all three scripts in config folder and it works without any problem. Anyway, If somebody is still interresting what I did, I tweaked those three scripts little bit to look like this:
runcommand-onstart.sh:
I also use xdotool in RetroPie to move mouse pointer to the right bottom corner. For bigger resolution screens those numbers should be higher I suppose. If you are using xdotool, too or want to use it, simply install it and unmark that line, if not, leave it as it is (I also use it at boot in my start script when splash is playing, so my pointer is still at bottom, but for some people it is not necessary). The file is completely identical as the old one without xdotool line.#!/bin/bash #if ps2 was selected, then start gamepad_wrapper script to catch buttons combo to kill PCSX2 process if [[ $1 = 'ps2' ]]; then #xdotool mousemove 2000 2000 /usr/bin/python3 /opt/retropie/configs/all/gamepad_wrapper.py & fi
gamepad_wrapper.py:
I had to tweak this file little bit to match my controllers and purpose. Anyway I had few problems that I had to solve:-first of them was that only one of my controllers worked with this script (when gamepad object is created), now the button combo (SELECT+START) works with first controller connected, so it is little bit more universal for my purpose. This is because of cmd_output object I created.
-second problem was button code variables. I did not know what my codes for SELECT and START are, so I simply started ./gamepad_wrapper.py from terminal and pressed buttons, so I could see what numbers it prints (to do so, unmark print(event0.code) and if you want also print(event1.code))
-third problem was that if I use SELECT btn in my game and then START btn I quit the emulator. That's exactly what I want, but I do not want to do it everytime. Script waits for user button inputs at start and if correct button is pressed, it continues to next loop where it is waiting for second combo btn, if a wrong button was pressed, the combination is canceled and script waits for the first button again. As I said, it is not ideal, but it works. You can simply edit combo if you want for example to add third btn, etc. but I like it as it is.
I use 8bitdo SF30 pro controllers, so my wrapper looks like this:
#!/usr/bin/env python3 #imports necessary parts from evdev import InputDevice, categorize, ecodes import psutil from subprocess import Popen #creates object 'gamepad' to store the data import os cmd_output = os.popen('cat /proc/bus/input/devices | grep Handlers=event | grep js') gamepad = InputDevice("/dev/input/"+cmd_output.read()[12:19]) #button code variables (change to suit your device) button0 = 314 button1 = 315 #process to look for to kill when BOTH keys were pressed procName = '/usr/games/PCSX2' #!/usr/bin/env python3 #imports necessary parts from evdev import InputDevice, categorize, ecodes import psutil from subprocess import Popen #creates object 'gamepad' to store the data import os cmd_output = os.popen('cat /proc/bus/input/devices | grep Handlers=event | grep js') gamepad = InputDevice("/dev/input/"+cmd_output.read()[12:19]) #button code variables (change to suit your device) button0 = 314 button1 = 315 #process to look for to kill when BOTH keys were pressed procName = '/usr/games/PCSX2' #loop through pressed buttons in event0 for event0 in gamepad.read_loop(): if event0.type == ecodes.EV_KEY: if event0.value == 1: #print(event0.code); #Button 1 pressed if event0.code == button0: #loop through pressed buttons in event1 for event1 in gamepad.read_loop(): if event1.type == ecodes.EV_KEY: if event1.value == 1: #print(event1.code); #Button 2 pressed if event1.code == button1: for process in psutil.process_iter(): if procName in process.cmdline(): process.terminate() exit() break; #Button 2 not pressed break;
Last script runcommand-onend.sh is identical:
#!/bin/bash #if ps2 was selected and buttons combo was pressed cleanup the Python wrapper process if [[ $1 = 'ps2' ]]; then PROCS=$(ps aux | grep gamepad_wrapper.py | awk '{ print $2 }') for PROC in ${PROCS[@]} do kill "$PROC" done fi
I hope my explanation is sufficient.
-
I tried your solution but cannot seem to get the script to work. I am not a python coder so I have no idea what these errors mean. Any insite would be appreciated. I took your gamepad_wrapper.py and ran it in a terminal to try to get the proper controller codes by uncommenting the print statements and received the following:
retropie@retropie:/opt/retropie/configs/all$ ./gamepad_wrapper.py
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/evdev/device.py", line 125, in init
fd = os.open(dev, os.O_RDWR | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event6 'During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/retropie/configs/all/./gamepad_wrapper.py", line 10, in <module>
gamepad = InputDevice("/dev/input/"+cmd_output.read()[12:19])
File "/usr/local/lib/python3.10/dist-packages/evdev/device.py", line 127, in init
fd = os.open(dev, os.O_RDONLY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event6 'here is the contents of my /dev/input directory:
retropie@retropie:/dev/input$ ls -la
total 0
drwxr-xr-x 4 root root 460 Oct 14 10:02 .
drwxr-xr-x 20 root root 4380 Oct 14 10:02 ..
drwxr-xr-x 2 root root 160 Oct 14 10:02 by-id
drwxr-xr-x 2 root root 200 Oct 14 10:02 by-path
crw-rw---- 1 root input 13, 64 Oct 13 18:25 event0
crw-rw---- 1 root input 13, 65 Oct 13 18:25 event1
crw-rw---- 1 root input 13, 74 Oct 13 18:25 event10
crw-rw---- 1 root input 13, 75 Oct 13 18:25 event11
crw-rw---- 1 root input 13, 76 Oct 13 18:25 event12
crw-rw---- 1 root input 13, 77 Oct 13 18:25 event13
crw-rw---- 1 root input 13, 78 Oct 13 18:25 event14
crw-rw---- 1 root input 13, 66 Oct 14 01:34 event2
crw-rw----+ 1 root input 13, 67 Oct 14 10:02 event3
crw-rw---- 1 root input 13, 68 Oct 14 01:34 event4
crw-rw---- 1 root input 13, 69 Oct 14 01:34 event5
crw-rw----+ 1 root input 13, 70 Oct 13 18:25 event6
crw-rw---- 1 root input 13, 71 Oct 14 01:34 event7
crw-rw---- 1 root input 13, 72 Oct 13 18:25 event8
crw-rw---- 1 root input 13, 73 Oct 13 18:25 event9
crw-rw----+ 1 root input 13, 0 Oct 13 18:25 js0
crw-rw----+ 1 root input 13, 1 Oct 14 10:02 js1
crw-rw---- 1 root input 13, 63 Oct 13 18:25 mice
crw-rw---- 1 root input 13, 32 Oct 14 01:34 mouse0what else should I post.
thanks for any help you can give.
Scott -
I have tried your solution but am having trouble with the antimicro progam itself. It launches just fine and the scripts onstart and onend work. I am having problems configuring antimicro. I have read the wiki for it and have tried to no avail. There does not seem to be a forum for help for the antimacro program itself. Any suggustions would be appreciated.
-
I found this can be done with the -nogui parameter using the nightly build of pcsx2. Not sure if this applies to the version Retropie uses. I had a hard time finding this solution when searching the web.
In pcsx2 I set a hotkey for Shut Down Virtual Machine. With the -nogui parameter pcsx2 will exit when you press the shutdown hotkey.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.