@y-ello said in How to add a GPIO button to a Retropie (Rpi 3B+) build?:
Can I use a GPIO wired push button for exit emulator? how?
Assuming you have a the button wired to a GPIO (there's tons of tutorials and documents on using a RPI with a button), you can use something like GPIONext to run a script whenever you press the button.
RetroArch has a network control interface, to which you can send commands from the script you attach to the button press (pause RA, open the menu, exit, etc.) - see more details here. Since most emulators in RetroPie are just libretro cores and run within RetroArch, it might be enough to cover most emulators, but you can also simulate a keyboard with GPIONext and simulate a key press for the button push (i.e. for opening the MAME menu).