to exit a PC game by external button, depends on the game itself.
the game has to support it.
some games blocks or does not recognize any external input (anti cheat / anti bot system).
so you need to test this:
on windows, you can kill all windows processes this way (excluding specific tasks/processes):taskkill /F /FI "USERNAME eq %username%" /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne dwm.exe" /FI "IMAGENAME ne cmd.exe" /FI "IMAGENAME ne notepad.exe"
explorer.exe and dwm.exe are better excluded.
cmd.exe for this project too.
notepad.exe is an example, to exclude an specific task
Next step is recognizing an external input.
Try this hybrid solution with Autoit script (an batch enclosed):
goto your AM folder (where attract.exe is). Create and compile this autoit script (for example : Killall.exe)
#include <Misc.au3>
While 1
; 55 = U key
If _IsPressed ("55") Then
Sleep(300)
FileDelete(@TempDir & "\cmd.bat")
FileWrite(@TempDir & "\cmd.bat", "@echo off" & @CRLF & 'taskkill /F /IM attract.exe' & @CRLF & 'taskkill /F /FI "USERNAME eq %username%" /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne dwm.exe" /FI "IMAGENAME ne cmd.exe"' & @CRLF & 'cd "C:\attract"' & @CRLF & 'start /MAX attract.exe')
Run(@TempDir & "\cmd.bat")
Exit
EndIf
WEnd
Create this config in AM:executable cmd
args /c start Killall.exe & "[romfilename]"
rompath C:\attract\EMU\PC Games\ROMS
romext .lnk
If you start a file from AM, Killall.exe starts too.
If you press U on keyboard:
a file cmd.bat is created in TEMP folder
all processes are killed (except: explorer.exe, dwm.exe, cmd.exe)
C:\attract\attract.exe starts