stonev Posted December 28, 2025 Posted December 28, 2025 33 minutes ago, JoeViking245 said: Try LCtrl instead of LControl Thanks for the idea. Unfortunately, the same "invalid hotkey" error remains. I tried testing a bit further, abandoning the %FireKey% variable altogether and just hard-coding {LCtrl} in the appropriate places. The good news is that when I run the script with a keylogger/checker, it acts as intended: F1 turns on the script with tooltip confirmation, pressing left control begins an auto press of left control every 50ms or so, with the ability to press left control during the sequence without interrupting it, and pressing F1 again turns it off (with tooltip confirmation). The bad news is that trying this with an actual game (Forgotten Worlds) does *not* work. I can see the tooltip when I press F1, but pressing left control doesn't seem to start the firing sequence. I've heard-tell of AHK and MAME not playing well together; maybe this is one of those instances? Quote
JoeViking245 Posted December 28, 2025 Posted December 28, 2025 15 minutes ago, stonev said: I've heard-tell of AHK and MAME not playing well together; maybe this is one of those instances? Some emulators need a more "literal" or "defined" key press. Can try adding to the top if the script SetKeyDelay, 0, 50 1 Quote
stonev Posted December 28, 2025 Posted December 28, 2025 7 minutes ago, JoeViking245 said: Some emulators need a more "literal" or "defined" key press. Can try adding to the top if the script SetKeyDelay, 0, 50 Progress! So adding that line made it work in Mame!!! Just to clean up the script a little... I still can't seem to use the %FireKey% variable on the first line of the Autofire loop. So to snip out part of my code: <FireKey := "{LCtrl}"> and <Send %FireKey%> work in tandem. However, if I use <~%FireKey%::>, I get the "invalid hotkey" error on that line. The only way to fix this is to change that line to <~LCtrl::>, that is, hard-code the key instead of using the variable. Not a deal-breaker by any means, but still a little strange. Quote
stonev Posted December 28, 2025 Posted December 28, 2025 Additionally, I've added the following to the bottom of the script: Esc::ExitApp Unfortunately, this kills the script with the first Esc and kills the game (as usual) with the second. Is there a way to kill the script and the game with a single press? Or better yet, kill the AHK script as a result of Mame exiting? Quote
JoeViking245 Posted December 29, 2025 Posted December 29, 2025 1 hour ago, stonev said: Additionally, I've added the following to the bottom of the script: Esc::ExitApp Unfortunately, this kills the script with the first Esc and kills the game (as usual) with the second. Is there a way to kill the script and the game with a single press? Or better yet, kill the AHK script as a result of Mame exiting? If the script is placed in the Running Script section for the emulator, the escape routine is not necessary [in this case]. When the emulator exits, the 'running script' is abandoned/forced closed, or as you say, killed. . In your case, I'm guessing it's an additional app to those games, set to Run Before.... You can use: $Esc:: { WinClose, ahk_exe mame.exe ExitApp } Quote
Jayinem Posted December 29, 2025 Posted December 29, 2025 (edited) So I have all of my music in Launchbox and that part is easy just add the mp3 add VLC Media Player as emulator and it plays. The more difficult part is doing everything while VLC Media Player stays in the tray and doesn't pop up every time you want to change a song. I've mostly gotten that done though the songs do play in the tray fine but the actual issue is using media keys to change songs or pause/play it. I've mostly had it working for 2 years now but it doesn't always work. I'm using ControlSend which I believe should make the app think you're activating it but that's not exactly working all of the time sometimes I have to go activate VLC myself to get the media keys to work again, and it goes away a lot more than it works. Here is my script for pause/play changing a song forwards or backwards is the same except for putting forwards or backwards instead of play_pause. Can the script be improved in any way to make it work 100% of the time? It seems nothing I've tried can reactivate it to allow the keys to work except me clicking on the app myself in the tray. #SingleInstance force SetTitleMatchMode, 2 DetectHiddenWindows, on if not A_IsAdmin Run *RunAs "%A_ScriptFullPath%" VLC:="VLC media player ahk_class Qt5QWindowIcon" ~Media_Play_Pause:: If WinExist * - VLC media player ;The VLC window does always end with " - VLC media player". WinGetTitle, VLC WinActivate VLC sleep 1000 ControlSend, , {Space}, %VLC% ; Return It also just behaves very randomly which you wouldn't think of happening from an ahk script but right now my next song and previous song keys are working yet my pause/play will not despite it being the exact same script (other than media_play_pause instead of media_next or media_prev and I checked these are correct inputs) Edit: Never paid attention under hotkeys VLC has global keys (it's kind of hard to tell unless you scroll to the top and there's just an empty white space you enter them in) I put the media keys in there and they work even if VLC is minimized. No AHK needed. Edited December 29, 2025 by Jayinem Quote
stonev Posted December 29, 2025 Posted December 29, 2025 16 hours ago, JoeViking245 said: In your case, I'm guessing it's an additional app to those games, set to Run Before.... You can use: $Esc:: { WinClose, ahk_exe mame.exe ExitApp } Ok, you guessed correctly! I'm using this script on a game-by-game basis; the use case (for me) is pretty narrow. That said - and sorry I didn't explain this - the above script works when I press the Esc key (i.e., mame and ahk script exit). However, I typically exit a game using the Exit Game option on the pause screen, which I naively assumed was identical to pressing Esc. It seems that it's not though: Exiting via the pause screen exits mame but the ahk script is still running. I have to press Esc again to close the ahk script. Is there an way to close the ahk script upon exiting mame via the pause screen? Quote
JoeViking245 Posted December 29, 2025 Posted December 29, 2025 42 minutes ago, stonev said: Is there an way to close the ahk script upon exiting mame via the pause screen? Ahh... The ol' exit from the Pause Menu routine. You've got several options, but the easiest one to convey is (not tested, but "looks good in print"....) In the Exit Script section of the emulator, add: WinClose, MyScript.ahk - AutoHotkey Change MyScript.ahk to the actual name of your script.ahk Quote
stonev Posted December 29, 2025 Posted December 29, 2025 Thanks for sticking with me on this, @JoeViking245. That option didn't work for me. I couldn't exit from the pause screen and when I hit Esc, the game ended but the script was still running. Although the script I'm using is relatively complex, I'd be interested to know how folks navigate using, say, a simple key remapping script for specific Mame games. Surely they don't want the remapping to persist after the game is over. I've looked online for solutions, but many of the involve "IfWinActive", which would be problematic for a script that is meant to work with a few games. Also, for me, the window title seems to include the Mame version so I'd have to remember to change the script with every Mame update. I'd still be interested in having the ahk close command within the script itself, but failing that, is there a way to globally shut down ahk upon exiting a game? Quote
stonev Posted December 29, 2025 Posted December 29, 2025 A little update: I tweaked the original exit script: $Esc:: { WinClose, ahk_exe mame.exe ExitApp } ..and removed the "$" so now it's just Esc:: { WinClose, ahk_exe mame.exe ExitApp } ...and this seems to work. Would there be any unforeseen consequences of removing the "$" that might make this change inadvisable? Also, I got rid of the Tooltip code and replaced it with: ; --- Function to Toggle --- ToggleAutoFire: AutoFire := !AutoFire ; Flip the state (true to false, false to true) SoundBeep, (%Autofire%+1)*250 Return Now there's an audible beep when I toggle AutoFire on and off. The tone is higher for "on" (500hz) and lower for "off" (250hz). 1 Quote
JoeViking245 Posted December 30, 2025 Posted December 30, 2025 4 hours ago, stonev said: Would there be any unforeseen consequences of removing the "$" that might make this change inadvisable? Nope! If it works, stick with it. Like the audible beep idea. 1 Quote
stonev Posted December 30, 2025 Posted December 30, 2025 Ok, so I peeked in at the AHK forums and yet another helpful internet friend tweaked the code so that the LCtrl variable issue is fixed AND the script works for a second player! Holding down the fire to get a powered attack while autofire is on can be hit-and-miss but I don't think that's fixable given the absolute barrage of button presses the game has to take in. In any case, for anyone who finds this, here's the working script: ; --- Configuration --- SetKeyDelay, 0, 50 ToggleKey1 := "LShift" ; Key to turn P1 autofire on/off FireKey1 := "LCtrl" ; The P1 button to spam (Left Control) ToggleKey2 := "w" ; Key to turn P2 autofire on/off FireKey2 := "a" ; The P2 button to spam (Left Control) Interval := 50 ; Milliseconds between fire button presses (adjust for speed) ; --- Variable --- AutoFire1 := AutoFire2 := false ; Start with P1/P2 autofire off ; --- Toggle Hotkey --- Hotkey, %ToggleKey1%, ToggleAutoFire1 Hotkey, %ToggleKey2%, ToggleAutoFire2 ; --- Main Autofire Timer (Controlled by the toggle) --- Hotkey, ~%FireKey1%, FireKey1 Hotkey, ~%FireKey2%, FireKey2 Return FireKey1: ; When the P1 FireKey is pressed down (~) If (AutoFire1) { ; If P1 autofire is ON Send,% "{" FireKey1 "}" ; Press the P1 fire button SetTimer, FireKey1, -%Interval% } Return FireKey2: ; When the P2 FireKey is pressed down (~) If (AutoFire2) { ; If P2 autofire is ON Send,% "{" FireKey2 "}" ; Press the P2 fire button SetTimer, FireKey2, -%Interval% } Return ; --- Function to Toggle --- ToggleAutoFire1: AutoFire1 := !AutoFire1 ; Flip the P1 state (true to false, false to true) SoundBeep, (%Autofire1%+1)*250 Return ToggleAutoFire2: AutoFire2 := !AutoFire2 ; Flip the P2 state (true to false, false to true) SoundBeep, (%Autofire2%+1)*250 Return ; --- Exit Script --- Esc:: { WinClose, ahk_exe mame.exe ExitApp } Happy gaming! 1 Quote
Jayinem Posted 20 hours ago Posted 20 hours ago (edited) JoeViking I don't know if you'll help me because you might not like that I'm running two Launchboxs at the same time one is sandboxed. I'm trying to make sure both are forced open I can run them fine on their own but when running a loop I can't just use the ahk_exe because it detects that there's already a Launchbox.exe open so I tried ahk_class which does have a different one however as soon as I do that no matter what perimeters I put in the system keeps trying to run the sandboxed one over and over and it crashes my PC? The loop worked when it was 1 Launchbox and it didn't keep trying to open it over and over only when I run the ahk_class does it do that. Some of the ;'s are just experiments on my end disregard them. #NoEnv SendMode Input SetWorkingDir %A_ScriptDir% #SingleInstance, Force SendMode Input SetWorkingDir %A_ScriptDir% iTC_EXE = "c:\Launchbox\[DefaultBox] LaunchBox.exe.lnk" iTC_Path = "c:\Launchbox\" ahk_class = DefaultBox ;ahk_class = ahk_class Sandbox:DefaultBox:HwndWrapper[LaunchBox.exe loop { Process, Exist, %ahk_class% If (ErrorLevel = 0) { Run, "C:\Launchbox\[DefaultBox] LaunchBox.exe.lnk" sleep 10000 ;WinMaximize A ;Send #+{Right} sleep 100 Send #+{Left} ;sleep 3000 } Else { sleep 5000 } } Edited 20 hours ago by Jayinem Quote
JoeViking245 Posted 19 hours ago Posted 19 hours ago 1 hour ago, Jayinem said: as soon as I do that no matter what perimeters I put in the system keeps trying to run the sandboxed one over and over It's not seeing the ahk_class you told it to look for. Did you use WindowSpy to get the class name? ahk_class needs to be spelled out as you have in your commented ahk_class line. But try putting it in the actual Process, Exist line. You have SendMode set twice (though shouldn't cause an issue). Quote
Jayinem Posted 19 hours ago Posted 19 hours ago (edited) 4 minutes ago, JoeViking245 said: It's not seeing the ahk_class you told it to look for. Did you use WindowSpy to get the class name? ahk_class needs to be spelled out as you have in your commented ahk_class line. But try putting it in the actual Process, Exist line. You have SendMode set twice (though shouldn't cause an issue). I was experimenting I did have the full ahk_class on the 2nd line as active but I have to cut it off in the middle because the numbers change every time and aren't persistent. That's why I was trying to put a smaller amount of it because of it changing. I wasn't sure the exact amount of it I needed to put in there but when running the 2nd line it still crashes my computer. Like I just ran it now LaunchBox ahk_class Sandbox:DefaultBox:HwndWrapper[LaunchBox.exe;;6f7dd556-1765-4827-bb44-f8e02fab50e3] ahk_exe LaunchBox.exe ahk_pid 14776 All of those numbers and letters after Launchbox.exe;; change every time I check it. If I run ahk_class Sandbox:DefaultBox:HwndWrapper[LaunchBox.exe it still tries to run the loop over and over regardless if the Launchbox is active or not. Edited 19 hours ago by Jayinem Quote
JoeViking245 Posted 18 hours ago Posted 18 hours ago 26 minutes ago, Jayinem said: If I run ahk_class Sandbox:DefaultBox:HwndWrapper[LaunchBox.exe it still tries to run the loop over and over regardless if the Launchbox is active or not. Sounds like you need to try to find a different way to find the one in SandBox. Maybe checking if it exists based on the window title? or if sandbox.exe (or whatever it is) is running. Regardless, I don't think I can help. I've never used sandbox and have no intention to install it just to test. If the above doesn't help any, maybe someone who uses it can chime in. 1 Quote
Jayinem Posted 18 hours ago Posted 18 hours ago 6 minutes ago, JoeViking245 said: Sounds like you need to try to find a different way to find the one in SandBox. Maybe checking if it exists based on the window title? or if sandbox.exe (or whatever it is) is running. Regardless, I don't think I can help. I've never used sandbox and have no intention to install it just to test. If the above doesn't help any, maybe someone who uses it can chime in. That's cool no worries thanks anyways. 1 Quote
Jayinem Posted 17 hours ago Posted 17 hours ago (edited) @JoeViking245 I think I've mostly solved it actually by taking your advice on using the sandbox as the app it checks for the sandbox not the sandboxed app so I'm no longer asking for help with the sandbox. The only issue I'm having is I keep getting the popup "another instance of Launchbox is running" would there be another loop I could run to check for that popup and always close it? or always keep it hidden? I really just don't want to ever see that popup again regardless I've tried to run scripts in the past to keep it from coming up but never was able to. Actually I just discovered I still have another problem. The loop still keeps running and keeps trying to focus in on the sandboxed Launchbox. So it still is running the loop over and over just not crashing my computer any longer. Edited 16 hours ago by Jayinem Quote
JoeViking245 Posted 16 hours ago Posted 16 hours ago 13 minutes ago, Jayinem said: The only issue I'm having is I keep getting the popup "another instance of Launchbox is running" would there be another loop I could run to check for that popup and always close it? Add a sleep timer after finding a Process (e.g. LaunchBox.exe) doesn't exist, then do another one (check for the process) to make sure before attempting to [re]start it. Then you wouldn't have to worry about that popup at all. You might be able to check for a specific exe (been a while since I looked at Process stuff). If that's the case, look for your /LaunchBox/Core/LaunchBox.exe. (As in, the one in the Core folder because that's the one that will be running. Not the one in the root folder.) 1 Quote
Jayinem Posted 16 hours ago Posted 16 hours ago (edited) If I put the sleep like this outside of the bracket If (ErrorLevel = 0) ; If it is not running sleep 7000 { I get Error: ELSE with no matching IF Line# ----- 022: Else The program will exit. But if I have it in the bracket like this If (ErrorLevel = 0) ; If it is not running { sleep 7000 I still get the other instance popup. I found an old script that gets rid of the other instance popup though actually, but it's not 100% solved my cursor keeps turning into an hour glass and I lose focus on whatever I'm doing when the loop hits so it's distracting. Also in the taskbar the sandboxed lanchbox keeps turning orange and blinking like if something is trying to be ran on it, obviously the loop causing it. So it's still trying to run constantly instead of doing nothing if it's open. Edited 16 hours ago by Jayinem Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.