I just realised that you were asking about emulationstation. There is a file called "es_input.cfg"; delete this file and emulationstation starts over with controllers. The official way in retropie; Retropie Setup Script >> Manage Packages >> Manage Core Packages >> EmulationStation >> Configuration / Options >> Clear / Reset EmulationStation Input Configuration.
To remap "exit" in mame; hit tab for the menu, "input (general)", "User Interface", "UI Cancel"
I'll give that a whirl. I've learned my lesson on being VERY careful what you set "UI Cancel" to as I painted myself into a corner on the Android version of mame.
Also, I would have never called it "UI Cancel". When I think of that, I think of the popup menu disappearing(or shall we say, canceling?) , and returning you to the game, not exiting out of MAME entirely. But then again, we are talking about MAME/MESS here, where any sort of UX is instantly tossed out of the window.