Ok I ran into a bunch more problems configuring all my exit keys. I realized that I want to quit each emulator "cleanly" so it has time to save its config, delete temp files etc.
For example, Retroarch (sic!) extracts zip files for roms, but only deletes the last extracted file on a clean exit. So if I use the exit key, which kills retroarch, it leaves all those files behind.
I found that most emulators exit cleanly on "escape." Kega Fusion required the -fullscreen argument to force it to quit on escape instead of switching to windowed mode. Snes9x and Nestopia show a menu on escape. I could not change that behaviour. What were the authors smoking? I am considering switching all those over to retroarch to get some more sane behavior, if only retroarch wouldn't be such a usability trainwreck.
So I now chose an autohotkey script that sends "escape" to the emulator first, waits 2 seconds, and if we are not back in Attract Mode, it sends the exit key to force kill the emulator. I then chose a neutral exit key, I settled on "divide" on the numpad.
Here is my new script content.
Contents of "ArcadeCabinetHotkeys.ahk":
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Event ; For compatibility with Attract Mode
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#If ( not WinActive("Attract-Mode") )
Joy7::
If GetKeyState("Joy8")
{
SetKeyDelay, -1, 110 ; Need to press exit key longer than 100 ms, because Attract Mode only checks it every 100 ms
Send {Escape} ; Most Emulators quit with escape key so try this first
Sleep, 2000 ; wait a second
If ( not WinActive("Attract-Mode") ) ; are we back in Attract Mode yet?
{
Send {NumpadDiv} ; No: use Attract Mode exit key NumpadDiv
}
}
Return
#If