RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Universal Emulator Exit Button

    Scheduled Pinned Locked Moved Help and Support
    11 Posts 6 Posters 10.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      attisb
      last edited by

      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!

      mediamogulM herb_fargusH 2 Replies Last reply Reply Quote 0
      • mediamogulM
        mediamogul Global Moderator @attisb
        last edited by

        @attisb

        Which SNES emulator are you running?

        RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

        1 Reply Last reply Reply Quote 0
        • A
          attisb
          last edited by

          It's the stock one that launches.

          mediamogulM 1 Reply Last reply Reply Quote 0
          • mediamogulM
            mediamogul Global Moderator @attisb
            last edited by mediamogul

            @attisb

            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.

            RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

            A 1 Reply Last reply Reply Quote 0
            • herb_fargusH
              herb_fargus administrators @attisb
              last edited by

              @attisb https://github.com/RetroPie/RetroPie-Setup/wiki/RetroArch-Configuration#default-joypad-hotkeys

              input_enable_hotkey_btn = "nul"

              If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

              Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

              1 Reply Last reply Reply Quote 0
              • A
                attisb
                last edited by

                I've put this in the bottom of the retroarch.cfg file
                /opt/retropie/configs/all/retroarch.cfg

                input_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"

                W 1 Reply Last reply Reply Quote 0
                • A
                  attisb @mediamogul
                  last edited by

                  @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 GPIO

                  GPIO.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 = False

                  while True:
                  if (not quit_game) and (not GPIO.input(40)): # Exit button pressed
                  quit_game = True
                  device.emit(uinput.KEY_ESC, 1) # Press Escape key

                  if quit_game and GPIO.input(40): # Exit button released
                  quit_game = False
                  device.emit(uinput.KEY_ESC, 0) # Release Escape key

                  if (not quit_test) and (not GPIO.input(38)): # Exit button pressed
                  quit_test = True
                  device.emit(uinput.KEY_F12, 1) # Press Escape key

                  if quit_test and GPIO.input(38): # Exit button released
                  quit_test = False
                  device.emit(uinput.KEY_F12, 0) # Release Escape key

                  if (not quit_sys) and (not GPIO.input(37)):
                  quit_sys = True
                  os.system('sudo shutdown -r now')
                  break

                  #print quit_game
                  time.sleep(.04)

                  1 Reply Last reply Reply Quote 0
                  • W
                    wetriner @attisb
                    last edited by

                    @attisb

                    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 your input_enable_hotkey_btn line in your main retroarch.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.

                    1 Reply Last reply Reply Quote 0
                    • Z
                      Zigurana
                      last edited by

                      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?

                      If tetris has thought me anything, it's that errors pile up and that accomplishments dissappear.

                      mediamogulM 1 Reply Last reply Reply Quote 0
                      • hansolo77H
                        hansolo77
                        last edited by hansolo77

                        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:

                        https://www.reddit.com/r/raspberry_pi/comments/2yw4fn/finally_set_up_retropie_complete_with_a_gpio/cpdhtpu/

                        Who's Scruffy Looking?

                        1 Reply Last reply Reply Quote 1
                        • mediamogulM
                          mediamogul Global Moderator @Zigurana
                          last edited by

                          @Zigurana

                          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
                          

                          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post

                          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.