egutierg, you wanna map the UI Exit (I think) in the mame configuration. When you are running a mame game, hit the tab key, then search for UI Exit. I mapped it to the joystick buttons, Start and Select. You can choose something different if you want.
Let me know if you can’t find UI Exit; it may be called something else. I couldn’t find it initially.