With regard to exiting RetroArch.
For one of my own machines, I had to go through this process again of setting up a cabinet to work with Retroarch. It took me a bit to figure it out myself again, and like always it was pretty annoying. A lot of the articles and forum posts on control setups are oriented around new setups, rather than existing setups. Going through my own system pretty thoroughly, this is what i observed.
Configurations for controls are handled from most specific to least. So... game configurations are loaded first > then controller > then emulator > then retroarch. These all have to be cleared out of existing junk.
RetroArch does not offer a sweeping ONE EXIT KEY TO RULE THEM ALL. To create a single exit key, you will have to remove or change every single configuration that already exists with regard to hot keys and exit keys.
You can't just put the behavior for exiting in RetroArch's main configuration file (at the time of this writing) it has to go in each emulator as well.
This is the process I used to set up the exit key for my cab.
Configure keyboard hotkey behaviour for RetroArch. By setting it to use NO hotkey, it will remove hotkey default and set the "escape" key to automatically launch RGUI menu. Because "escape" is the normally the default emulator exit key, you will likely need to remap the exit key to something besides "escape" uless you've already done so. In my case, I use the "space" key.
1. sudo sh ~/RetroPie-Setup/retropie_setup.sh
2. Open Configuration/Tools -> RetroArch
3. Configure Hotkey behavior
4. Set it to no hotkey
5. Edit the following files: `/opt/retropie/configs/all/retroarch.cfg`, `/opt/retropie/configs/EACH_OF_YOUR_CONFIGURED_EMULATORs/retroarch.cfg`, `/opt/retropie/configs/all/retroarch-joypads/YOUR_CONFIGURED_JOYPADS.cfg` and change any occurrence of `inpux_exit_emulator`, `input_exit_emulator_btn` to use a new escape key. I use `inpux_exit_emulator="space"`. Make sure to remove any variation of `input_exit_emulator`, `input_exit_emulator_btn`, `input_enable_hotkey`, `input_enable_hotkey_btn`. There may be options (like input_enable_hotkey_axis) make sure to remove all of them except those that you've added.
MAKE SURE YOU ALSO MAKE THIS CHANGE HERE IN THE ARCADE FOLDER: `/opt/retropie/configs/arcade/retroarch.cfg`
If you removed the hotkey, but have ever configured any hotkey+ buttons in your gamepads, make sure you remove the configured buttons from the gamepad-specific cfg files or things will go haywire.
7. if using picade x-hat, map your new escape key to be the "esc" key in the boot/config: I use dtparam=escape=57 #(thats the space key)
By the way, for future reference, if you want to change the key command for launching RGUI menu, it's this configuration option: input_menu_toggle = "tilde" (or whatever)