Universal Emulator Exit Button
-
Hi I'm trying to create a button using the GPIO to exit the game, but can't seem to get it to work. Basically there is a python script running to check the pins. If the pin is pushed then it will send a keyboard command of ESCAPE, but it does not work with SNES for some reason. I tried it with N64 running a game and it worked fine.
I know the script is working and running since I have a separate pin to send a restart command and also two other pins to send the arrow up and arrow down keyboard command.
If I plug a keyboard into the Pi and hit ESCAPE on the keyboard it works.
I'm using the latest image of RetroPie with no modifications other than adding this script.
HELP!
-
Which SNES emulator are you running?
-
It's the stock one that launches.
-
That would make it lr-snes9x-next, which is one of the RetroArch cores. Does your script function with any of the other RetroArch cores? Without any modification, these cores expect Select+Start to exit the game. This can be changed to your liking by going to the RetoPie menu in Emulation Station and selecting the 'RetroArch' listing. Once inside the Rgui, navigate to 'Settings', the 'Configuration' and tun on 'Save Configuration on Exit'. Now, exit Retroarch and relaunch it and navigate to 'Settings', then 'Input' and finally 'Input Hotkey Binds'. There are a few ways to set this depending on your preference. Of course, this is just a guess as to what's wrong, but I know that 'Escape' alone won't exit RetroArch with RetroPie out of the box, so it's a good place to start looking.
-
@attisb https://github.com/RetroPie/RetroPie-Setup/wiki/RetroArch-Configuration#default-joypad-hotkeys
input_enable_hotkey_btn = "nul"
-
I've put this in the bottom of the retroarch.cfg file
/opt/retropie/configs/all/retroarch.cfginput_exit_emulator_btn = "escape"
input_enable_hotkey_btn = "nul"
input_exit_emulator = "escape"
input_enable_hotkey = "nul"with no success. I've even tried, changing the pin to send a F12 push instead.
input_exit_emulator_btn = "f12"
input_enable_hotkey_btn = "nul"
input_exit_emulator = "f12"
input_enable_hotkey = "nul" -
@mediamogul Went into there and it is showing correctly that it does use a hotkey and uses escape (or f12 when I was checking to see if it reads the file correctly). I tried to see if I click on it and then push the button to see if the it would change the setting and it does not.
I'm thinking RetroArch is not seeing the commands from the python script. Below is the script that is running:
import uinput
import time
import os
import RPi.GPIO as GPIOGPIO.setmode(GPIO.BOARD)
Up, Down, left, right, fire
GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(38, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)events = (uinput.KEY_ESC, uinput.KEY_F12)
device = uinput.Device(events)
quit_game = False
quit_test = False
quit_sys = Falsewhile True:
if (not quit_game) and (not GPIO.input(40)): # Exit button pressed
quit_game = True
device.emit(uinput.KEY_ESC, 1) # Press Escape keyif quit_game and GPIO.input(40): # Exit button released
quit_game = False
device.emit(uinput.KEY_ESC, 0) # Release Escape keyif (not quit_test) and (not GPIO.input(38)): # Exit button pressed
quit_test = True
device.emit(uinput.KEY_F12, 1) # Press Escape keyif quit_test and GPIO.input(38): # Exit button released
quit_test = False
device.emit(uinput.KEY_F12, 0) # Release Escape keyif (not quit_sys) and (not GPIO.input(37)):
quit_sys = True
os.system('sudo shutdown -r now')
break#print quit_game
time.sleep(.04) -
It seems to be that the controller joypad config hotkey_btn lines override the main
retroarch.cfg
. So it's possible that a CONTROLLER.cfg in/opt/retropie/configs/all/retroarch-joypads/
is overriding yourinput_enable_hotkey_btn
line in your mainretroarch.cfg
. Thereby making the exit hotkey require two buttons. By default there are hotkey lines generated for every controller that gets configured through emulationstation. So you may need to go into a controller file and remove that line for it to work as intended.My understanding of how retroarch handles hotkeys is, either no hotkeys, all single press hotkeys, or all double input hotkeys. Note that you can set your keyboard enable_hotkey and exit_hotkey on the same key in your
retroarch.cfg
, but that would limit you to being able to only use a single hotkey on your keyboard. But it is one way to emulate the single press. The restrictions apply to all input devices, so you can't have a controller with single press hotkeys and a keyboard with double input hotkeys at the same time.Although, since you're using a script, you should be able to emulate two keypresses if necessary. So you should be able to get it to work no matter how it's set up.
-
Hey, any update on this?
Up till now, this discussion has focused on RetroArch emulators, but I would like to include other systems as well, dosbox, scummvm, maybe even some of the ports.I guess something like a query for the running process, and sending the corresponding exit/kill-signal would be needed?
-
I have the RESET button on my NES case doing exactly what you're looking for (Universal Emulator Exit Button). I created a few scripts, and followed this guide more or less exactly as written:
-
There's also an option to execute shell commands from xboxdrv, making the process query and exit/kill-signal possible from a single controller mapping that could then be used universally throughout RetroPie. Although I haven't tested this yet myself, mapping a shell script to the 'select+start' combination that would accomplish this should look something like:
--ui-buttonmap back+start=exec:/path/to/script.sh
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.