it is really weird how this is works.  The script works fine in notepad, but mame just seems to ignore it entirely.  If i launch mame, and then alt-tab back to the desktop and press the key, it closes the mame executable. i just dont understand why it would work in xp and windows 8, but not windows 7.  I just tested it here on my work pc, which is also windows 7, but it still does not function.
i have two versions of the script, one which sends either the P or Esc command when escape key is either held or pressed, and other which is set to send the p key if p is pressed, or process close mame.exe if it is held....neither work in mame.  with the first one, mame exits immediately if esc is held or pressed.  with the second one, it pauses when p is pressed, but nothing happens when held.  if i alt-tab to the desktop with mame minimized, and hold the p key, it will close the mame executable like it should...just not while it is running.
is there something i'm doing wrong?
here are my scripts: ( i didn't write these, WXFORECASTER here on the forums created the first one for me years ago, i modified it for the second one.
/*
AUTHOR: WXFORECASTER 10/12/10
DESCRIPTION: DESIGN OVERRIDE SUCH THAT A SINGLE KEY PRESS AND KEY HOLD 
             GENERATE DIFFERENT FUNCTIONALITY
*/
/*
BEGIN HOLDESCAPE CODE
SET USER DEFINED VARIABLES BELOW
*/
timeToExit := 1.6    ;time in seconds key must be pressed before sending exit (this can be a decimal e.g. 1.5)
emulateKey := "esc"    ;the key we are pressing/emulating
pauseKey :="p"      ;your MAME pause key
exitKey := "esc"         ;your MAME exit key
exitScript := 0      ;0= leave script running, 1= close script when the MAME exit key is fired, 
;Make it so the following code only works if MAME is the active window
;#IfWinActive ahk_class MAME
;Establish Hotkey Mapping based on the emulate key above and trigger a chunk of code below (lblPauseExit)
Hotkey, $%emulateKey%, lblPauseExit
return
lblPauseExit:
KeyWait %emulateKey%, T%timeToExit%
      if ErrorLevel = 1 ;timeout was reached...exit MAME
      {
              send {Blind} {%exitKey% downtemp} ;Send MAME Exit
              send {Blind} {%exitKey% up}
                   if (exitScript = 1)
                      ExitApp
      }
      else
      {
         send {Blind} {%pauseKey% downtemp} ;Send MAME pause/unpause
         send {Blind} {%pauseKey% up}
      }     
return
HERE IS THE SECOND SCRIPT:
/*
AUTHOR: WXFORECASTER 10/12/10
DESCRIPTION: DESIGN OVERRIDE SUCH THAT A SINGLE KEY PRESS AND KEY HOLD 
             GENERATE DIFFERENT FUNCTIONALITY
*/
/*
BEGIN HOLDESCAPE CODE
SET USER DEFINED VARIABLES BELOW
*/
timeToExit := 1.6    ;time in seconds key must be pressed before sending exit (this can be a decimal e.g. 1.5)
emulateKey := "p"    ;the key we are pressing/emulating
pauseKey :="p"      ;your MAME pause key
exitKey := "esc"         ;your MAME exit key
exitScript := 0      ;0= leave script running, 1= close script when the MAME exit key is fired, 
;Make it so the following code only works if MAME is the active window
;#IfWinActive ahk_class MAME
;Establish Hotkey Mapping based on the emulate key above and trigger a chunk of code below (lblPauseExit)
Hotkey, $%emulateKey%, lblPauseExit
return
lblPauseExit:
KeyWait %emulateKey%, T%timeToExit%
      if ErrorLevel = 1 ;timeout was reached...exit MAME
      {
   Process, Close, mame.exe
                   if (exitScript = 1)
                      ExitApp
      }
      else
      {
         send {Blind} {%pauseKey% downtemp} ;Send MAME pause/unpause
         send {Blind} {%pauseKey% up}
      }     
return