ThePagel Posted May 28, 2021 Share Posted May 28, 2021 (edited) Solved Hello! I am trying to open a program after retroarch opens and then close it after retroarch closes. It opens but never closes. The script works flawlessly outside of launchbox. Can anyone tell me whats up? See my script below. SetTitleMatchMode, 2 winwait, RetroArch IfWinExist, RetroArch Run "..\..\Emulators\vgtranslate_server\serve.exe", ..\..\Emulators\vgtranslate_server\, Min WinWaitClose, RetroArch WinClose, \serve.exe NumpadAdd::Space NumpadSub::F4 Numpad7::F2 NumpadDot::Esc Numpad9::F7 Numpad8::F6 Numpad5::r Numpad6::p NumpadDiv::F8 NumpadMult::F3 =::F1 Edited May 29, 2021 by ThePagel Solved Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 28, 2021 Author Share Posted May 28, 2021 Oh, and I just realized "IfWinExist, RetroArch" is not needed and just a redundant step. Quote Link to comment Share on other sites More sharing options...
Your Friendly A.I Overlord Posted May 28, 2021 Share Posted May 28, 2021 WinClose, ahk_exe serve.exe Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 28, 2021 Author Share Posted May 28, 2021 6 minutes ago, Koroth said: WinClose, ahk_exe serve.exe Thanks but it didn't work. In fact it broke the script when attempting to run outside of launchbox. Quote Link to comment Share on other sites More sharing options...
Your Friendly A.I Overlord Posted May 28, 2021 Share Posted May 28, 2021 10 minutes ago, ThePagel said: Thanks but it didn't work. In fact it broke the script when attempting to run outside of launchbox. 58 minutes ago, ThePagel said: WinClose, \serve.exe Your original script is trying to close a window called \serve.exe. Replace that with "WinClose, ahk_exe serve.exe". And how did you add the script to LaunchBox? Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 28, 2021 Author Share Posted May 28, 2021 (edited) 12 minutes ago, Koroth said: Your original script is trying to close a window called \serve.exe. Replace that with "WinClose, ahk_exe serve.exe". And how did you add the script to LaunchBox? It's going off of the title to detect if retroarch is open and to close the server window. To go more in depth; I'm keeping this setup 100% portable. The title in the server window is the full path to the program. \serve.exe just happens to be the last bit. Settitlematchmode, 2 allows it to look for specific characters instead of the whole title. This script has been tested and works using ahk standalone. I want to avoid that for portability. Added the script in the opening script area in launchbox. Edited May 28, 2021 by ThePagel Quote Link to comment Share on other sites More sharing options...
Your Friendly A.I Overlord Posted May 28, 2021 Share Posted May 28, 2021 (edited) The easiest solution would be, in the "Running AutoHotKey Script" tab for RetroArch add: Run, "..\..\Emulators\vgtranslate_server\serve.exe", , Min NumpadAdd::Space NumpadSub::F4 Numpad7::F2 NumpadDot::Esc Numpad9::F7 Numpad8::F6 Numpad5::r Numpad6::p NumpadDiv::F8 NumpadMult::F3 =::F1 $Esc:: { WinClose, ahk_exe retroarch.exe WinClose, ahk_exe serve.exe } Edited May 28, 2021 by Koroth Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 28, 2021 Author Share Posted May 28, 2021 (edited) WinClose, ahk_exe serve.exe This doesn't work. Trust me, it was the first thing I tried when making this script. I think vgtranslate is python at it's base. Might be why? I've ran into oddities in the past with python programs that have been packaged into exe. But that shouldn't effect my original script. I'll try adding a loop in when I get home from work. That shouldn't be needed but obviously something is different with launchboxs ahk. Edited May 28, 2021 by ThePagel Quote Link to comment Share on other sites More sharing options...
Your Friendly A.I Overlord Posted May 28, 2021 Share Posted May 28, 2021 (edited) 2 hours ago, ThePagel said: WinClose, ahk_exe serve.exe This doesn't work. Trust me, it was the first thing I tried when making this script. To test I downloaded vgtranslate_server_v1.05 and used the following script in LaunchBox > Tools > Manage Emulators > RetroArch > Running AutoHotKey Script tab: SetWorkingDir D:\Downloads\vgtranslate_serve_v1.05 Run, serve.exe, , Min $Esc:: { WinClose, ahk_exe retroarch.exe WinClose, ahk_exe serve.exe } RetroArch and serve.exe both close when pressing the Escape key. Do you run serve.exe with admin privileges by any change? Edited May 28, 2021 by Koroth 2 Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 28, 2021 Share Posted May 28, 2021 38 minutes ago, ThePagel said: I think vgtranslate is python at it's base. Might be why? I doubt it. An executable file (.exe), by any other name is still an executable file. Unless the exe spawns another program. You stated that your script worked outside of LaunchBox, so we know "WinClose, \serve.exe" is a good command (provided you use "SetTtitleMatchMode, 2"). So it could spawn another exe, but \serve.exe happens to be in the windows title. 1 hour ago, ThePagel said: obviously something is different with launchboxs ahk. No. I think the issue is that your original script waits for RetroArch to close, then tries to close serve.exe. (hear me out....) If the script is in the Running AutoHotkey Script section for the emulator (which is where it should be as @Koroth stated), when the emulator (RA in this case) exits, LaunchBox closes out the Running AutoHotkey Script. So basically it never reaches the next line of the script. Which is to close serve.exe. Try Koroth's script as suggested where you set Escape to close RA and serve. Just is case, maybe switch the order of those 2 and close serve first. If "WinClose, ahk_exe serve.exe" still doesn't work, add in the "SetTitleMatchMode 2" at the top and change that line of the escape sequence to "WinClose, \serve.exe". 2 Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 28, 2021 Author Share Posted May 28, 2021 11 minutes ago, JoeViking245 said: I doubt it. An executable file (.exe), by any other name is still an executable file. Unless the exe spawns another program. You stated that your script worked outside of LaunchBox, so we know "WinClose, \serve.exe" is a good command (provided you use "SetTtitleMatchMode, 2"). So it could spawn another exe, but \serve.exe happens to be in the windows title. No. I think the issue is that your original script waits for RetroArch to close, then tries to close serve.exe. (hear me out....) If the script is in the Running AutoHotkey Script section for the emulator (which is where it should be as @Koroth stated), when the emulator (RA in this case) exits, LaunchBox closes out the Running AutoHotkey Script. So basically it never reaches the next line of the script. Which is to close serve.exe. Try Koroth's script as suggested where you set Escape to close RA and serve. Just is case, maybe switch the order of those 2 and close serve first. If "WinClose, ahk_exe serve.exe" still doesn't work, add in the "SetTitleMatchMode 2" at the top and change that line of the escape sequence to "WinClose, \serve.exe". Yup, that makes sense. I understand why that's not working now. 14 minutes ago, Koroth said: To test I downloaded vgtranslate_server_v1.05 and used the following script in LaunchBox > Tools > Manage Emulators > RetroArch > Running AutoHotKey Script tab: SetWorkingDir D:\Downloads\vgtranslate_serve_v1.05 Run, D:\Downloads\vgtranslate_serve_v1.05\serve.exe, , Min $Esc:: { WinClose, ahk_exe retroarch.exe WinClose, ahk_exe serve.exe } RetroArch and serve.exe both close when pressing the Escape key. Do you run serve.exe with admin privileges by any change? I'll need to figure out why that's not working for me. That was literally the first thing I tried when making this script. Quote Link to comment Share on other sites More sharing options...
ThePagel Posted May 29, 2021 Author Share Posted May 29, 2021 (edited) @Koroth @JoeViking245 Thank you both for helping me. Still no idea why ahk_exe wasn't working for me last night because its just fine today. I am not a fan of stealing retroarchs escape function so I made a ahk script to control when to open and to close vgtranslate then compiled it to exe for portability sake. On launch of retroarch, launchbox will now open vgtranslate_for_LaunchBox.exe instead of serve.exe. I noticed every time I changed from full screen to windowed or vice versa vgtranslate would think retroarch closed and in turn close vgtranslate. I made a loop and added a sleep to defeat that last hurdle. You both saved me from giving up so thank you! Check out the script below. SetTitleMatchMode, 2 DetectHiddenWindows, On SetWorkingDir %A_ScriptDir% winwait, RetroArch Run serve.exe, ,min Loop { WinWaitClose, RetroArch Sleep, 1000 IfWinExist, RetroArch continue IfWinNotExist, RetroArch break } WinClose ahk_exe serve.exe Edited May 29, 2021 by ThePagel 1 Quote Link to comment Share on other sites More sharing options...
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.