On my arcade machine I have it set in Mame to use coin and another button simultaneously to exit from game. Using the UI cancel built into MAME isn't the same as using Alt-F4 basically you are taking the built in Escape function in MAME and adding it to a button combo so it is cleanly shutting MAME down. Whatever works for anyone is great but the simplest solution is to use the one built into MAME.