@mitu thanks for the codeblocks sugerence i never ear about it.
In raspberry 3 retroflag cases if you use default script if you push power button it shutdown the pi and reset button reboot it.
With this code the power button, shutdown the pi saving changes and the reset button restart only emulationstation if you are in main menu, or exit game if you are in a game.
I checked pins and are the same but i dont know why in pi4 you push the button and the pi do nothing 😟