wxforecaster Posted December 10, 2015 Posted December 10, 2015 ;---------------------------------------------------------------------------- ; MAME ; MAME .147 ; by BBB & djvj & wxforecaster ; 1.3 ; ; Notes: ;---------------------------------------------------------------------------- ;---------------------------------------------------------------------------- ExitKey = Esc ; exit key PauseKey = p ; pause key KeyDelay = 2 ; how long, in seconds, do the hotkeys have to be held down to send their alternate function ;---------------------------------------------------------------------------- GUI_ID := FadeInStart() Hotkey, %ExitKey%, CloseProcess Run, %executable% %romName%, %emuPath%, Hide UseErrorLevel If(ErrorLevel != 0){ If (ErrorLevel = 1){ Error = Failed Validity }Else If(ErrorLevel = 2){ Error = Missing Files }Else If(ErrorLevel = 3){ Error = Fatal Error }Else If(ErrorLevel = 4){ Error = Device Error }Else If(ErrorLevel = 5){ Error = Game Does Not Exist }Else If(ErrorLevel = 6){ Error = Invalid Config }Else If(ErrorLevel = 7 || ErrorLevel = 8 || ErrorLevel = 9){ Error = Identification Error }Else{ Error = Mame Error } MsgBox Mame Error - %Error% } WinWait, MAME ahk_class MAME WinWaitActive, MAME ahk_class MAME Sleep, 700 ; Necessary otherwise the HyperSpin window flashes back into view GUI_ID2 := FadeInExit() Process, WaitClose, %executable% GUI_ID4 := FadeOutExit() WinActivate, Hyperspin ExitApp ; Key delay code has to be in CloseProcess because HyperLaunch will always call this label when the exit key is held down or pressed quickly. So CloseProcess must handle the key state accordingly. CloseProcess: KeyWait %ExitKey%, T%KeyDelay% ;Will generate error level 1 after timeout of delay If ErrorLevel { GUI_ID3 := FadeOutStart() WinClose, MAME ahk_class MAME } Else { Send {%PauseKey% down}{%PauseKey% up} } Return I've got the following MAME.ahk in the modules/MAME folder to launch the ROMs and to hopefully have a dual pause/escape key. The way the code is supposed to work is that the pressing of the escape key is mapped to the close process routine. If the escape key is held down for at least 2 seconds, the keywait times out, tripping an error which exits out of MAME. In any other condition, it should send the pause key. The exit aspect works just fine. If I hold down Esc for at least two seconds, MAME exits cleanly. However, if I release the escape key prior to two seconds, nothing happens. Can someone take a look and tell me where I messed up in the pause aspect? It's a simple send 'p' key down and up.
paulstevens Posted December 11, 2015 Posted December 11, 2015 I've never ever tried to program anything in AHK. That said, why not consider this: Instead of an IF <condition> ELSE, just do a regular IF. Pardon my cut/paste and psuedocode. I don't know AHK syntax: CloseProcess: KeyWait %ExitKey%, T%KeyDelay% ;Will generate error level 1 after timeout of delay If ErrorLevel { GUI_ID3 := FadeOutStart() WinClose, MAME ahk_class MAME } #end the if above. If your ESC key is held for 2 seconds, the above will close and exit. If not, it will fall down to the next line of code, sending the pause key down then up Send {%PauseKey% down}{%PauseKey% up} } You'll have to check {} and other syntax. Please understand I don't know AHK code, but the logic I think could work for you.
wxforecaster Posted December 11, 2015 Author Posted December 11, 2015 I've been a developer for over 20 years. if {some condition} exit end some non-exit code is exactly the same as: if {some condition} exit else: do something else end The latter is preferred syntax, and both are identical. That's not why this is failing as I can generate a message box just fine in the non-exit code. The issue is that I can press keys physically and interact with MAME just fine (coin up, start, pause, move, jump, etc...), but AHK isn't sending them to the window no matter which keys I try. I checked the ActiveWindow and it's MAME. It's gotta be something with the way HyperLaunch's main AHK script works and loads in the module-specific AHKs. It's like it can take in keyboard input, but not send output. Anyone else?
paulstevens Posted January 8, 2016 Posted January 8, 2016 wxforecaster, did you ever get anywhere with this? Your idea is a good way to reduce buttons on a control panel. Thanks.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.