A script that can suspend and resume another ahk script when another program loses/gains focus?

Ask gaming related questions
RetroSpin
Posts: 2
Joined: 13 Aug 2018, 00:47

A script that can suspend and resume another ahk script when another program loses/gains focus?

13 Aug 2018, 01:11

Hello, I apologize if the title seems confusing (it's the best that I can come up with right now), but I will try to explain what my request is in better detail.

I would like to have a ahk script that can suspend another compiled ahk script when a program loses focus in windows (windows 7 to be exact). Then when that said program regains focus, have the same script resume the compiled script it suspend earlier.

To go in greater detail: my pc setup is for an arcade cabinet, and the program I reference earlier is an arcade frontend called Hyperspin. As for the compiled ahk script, it is a screensaver that starts up a video after set amount of time of inactivity. The problem is, the script will start up a video even when Hyperspin is no longer in focus, which causes some issues with whatever game is running at that time. So that's why I would like to have a ahk script that can suspend the screensaver script when Hyperspin is not in focus, then resume the screensaver script when Hyperspin regains its focus.

I tried looking into how to write the ahk script myself, but I barely have any basic understanding of AutoHotKey (to put it kindly). I did end up guessing on what to write, but honestly I have no idea if the script even does anything close to what I want it to do, that is if it does anything at all. I just know it doesn't error out when it runs. lol

Code: Select all

Nothing to see here...
My pathetic attempt of a script.


Anyways, any help to create a working script will be greatly appreciated.
Last edited by RetroSpin on 15 Aug 2018, 16:55, edited 1 time in total.
RetroSpin
Posts: 2
Joined: 13 Aug 2018, 00:47

Re: A script that can suspend and resume another ahk script when another program loses/gains focus?

15 Aug 2018, 16:51

Well after many trial and error attempts, I believe I finally came up with a working script that does what I originally wanted.

Code: Select all

#Persistent

DetectHiddenWindows, On
SetTitleMatchMode, 2

sleep, 10000

setTimer, check
return

check:
IfWinActive, ahk_exe HyperSpin.exe 
ifWinNotExist, Screensaver.exe

run, C:\HyperSpin\Screensaver\screensaver.exe

IfWinNotActive, ahk_exe HyperSpin.exe
IfWinNotActive, ahk_exe vlc.exe
{
Process, Close, Screensaver.exe
sleep, 5000
}
return 
I still need to do some more testing to make sure no other issues arrive (as well as clean up the code a little better), but so far the script seems to be working out fine. There is one thing that I am concerned about. I've read that using the process, close command will not free up any system resources from the closed process. Is this still true? And if so, could this become a potential issue with my script?

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 12 guests