i solved this in a simpler way.
I made a python script which generates a "AltF4" keyboard event:
#!/usr/bin/python import keyboard keyboard.send('Alt+f4')(it requires the pyhon keyboard library. If you don't have it on your system, then give the command "pip install keyboard" to install it.
and added a line to call this script in /opt/retropie/configs/all/autostart.sh:
emulationstation #auto sudo python /opt/altf4/altf4.pyfor me it's solved. I still think functionality like this should be included in the normal retropie build. This prevents a security issue (someone can press alt-f4 in emulation station and will have access to the system with sudo rights with entering any password)