Mame uses raw keyboard data so ahk scripts that do simulated keypreses won't work on it, sorry.
But it looks like what you are trying to do is have two keys combined do a special function. (Pause, exit and enter?)
Simply remap your keys in mame. It supports "and" so you can have ui exit mapped to "1 and 4" instead of just "esc"
Check the mame faq if you have trouble mapping two keys together as an "and".