Build Your Own Arcade Controls Forum
Main => Software Forum => Topic started by: Wade007 on July 10, 2012, 12:26:58 am
-
I'm building the last part of my arcade cabinet; PC arcade ports.
I'm launching the executable from Mala using an AHK script so I can remap a few keys along the way.
Everything works fine except that as you know, PC games can be "quit" via an on-screen menu and not just a button combo as set up by AHK. If the user quits via the on-screen menu with the mouse then the AHK script is still left running. How can I fix this?
For example, if I launch a game called Neverball, my script is set to kill the program using the following script (ending part of script) :
~2 & ~4:: ; This is my chosen 2-button key combo for quitting all games and emulators
Process, Close, Neverball.exe
ExitAPP
return
The above (closing) script works fine, but again, if the user uses the on-screen menu to "Quit to Desktop" using the mouse instead of hitting 2 & 4 together, then AHK ends up running in the background after the PC game has quit. It never gets to the "ExitAPP" part. If I'm not careful, I can have several AHK programs running at once in the background.
Isn't there some sort of "Win-Wait Program" command that will sense if the game (Neverball.exe) has quit by itself and then shut down the AHK script and then close Auto Hot Key?
I'm sure this is an easy fix, I'm just not quite sure on the details. Thanks in advance for any help. :)
-
Isn't there some sort of "Win-Wait Program" command that will sense if the game (Neverball.exe) has quit by itself and then shut down the AHK script and then close Auto Hot Key?
I would use WinWaitClose. See the commands WinWaitClose and SetTitleMatchMode in the ahk help file for the relevant info.
Basically you would put something like this immediately before the hotkeys part of your script.
WinWaitClose, Neverball
exitapp
The script should exit when the Neverball game window no longer exists.
:cheers:
-
Thanks nitz for your quick response.
I think I correctly added in the code suggested....maybe. I must have done something wrong because it's not quite working. Could you please help me again?
The following is my full script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance force
SetWorkingDir, C:\Arcade\PC Arcade Ports\Neverball
Run, C:\Arcade\PC Arcade Ports\Neverball\Neverball.exe
LCtrl::~LButton
LAlt::~RButton
Space::LShift
LShift::F1
z::F2
x::F3
c::ESC
a::~LButton
s::~RButton
q::LShift
w::F1
e::F2
[::F3
]::ESC
WinWaitClose, Neverball
exitAPP
~2 & ~4::
Process, Close, Neverball.exe
ExitAPP
return
-
Try moving all the hotkeys below the WinWaitClose command like this:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance force
SetWorkingDir, C:\Arcade\PC Arcade Ports\Neverball
Run, C:\Arcade\PC Arcade Ports\Neverball\Neverball.exe
WinWait, Neverball
WinWaitClose, Neverball
exitAPP
LCtrl::~LButton
LAlt::~RButton
Space::LShift
LShift::F1
z::F2
x::F3
c::ESC
a::~LButton
s::~RButton
q::LShift
w::F1
e::F2
[::F3
]::ESC
~2 & ~4::
Process, Close, Neverball.exe
ExitAPP
return
Anything that you want your script to automatically do (ie not tied to a hotkey) needs to go before the hotkeys.
I've also added a WinWait command so that the script waits for the window to actually exist before it waits for it not to exist - without the WinWait command, even the slightest delay between running Neverball and the window coming into existence will probably cause the script to just exit right away.
Cheers. :cheers:
-
Excellent nitz!! Once again...Thank you!!
Script works perfectly. You've been a great help. Thanks for your patient support and expertise.
Cheers!! :cheers:
PS for those trying to solve this same issue: There's one thing I had to remind myself when using the WinWait and WinWaitClose commands; The next word or words on the line of code indicates the name or title of the Window, not necessarily the name of the game nor the executable name of the PC game being played. I had go into each game to adjust the settings to be NON-full screen at first so I could triple-check the Window title displayed and then plug that name in the AHK script so it would work correctly. See comment notes below regarding these correctly updated lines of AHK code. Once I entered the correct Window titles, everything worked out perfectly.
WinWait, Neverball 1.5.4; Neverball 1.5.4 is the title of the game WINDOW opening, NOT simply "Neverball"
WinWaitClose, Neverball 1.5.4 ; Neverball 1.5.4 is the title or name of the game WINDOW closing.