Seems like #IfWinActive supports WinTitle, but doesn't support variables, otherwise I'd use something like
Code: Select all
#IfWinActive ahk_id %A_ScriptHwnd%
The solution (thanks to Lexikos and the other pals):
Code: Select all
GroupAdd Self, % "ahk_pid " DllCall("GetCurrentProcessId") ; Create an ahk_group "Self" and make all the current process's windows get into that group.
#IfWinActive ahk_group Self
... ; here goes your code, which would get executed only if any of script's windows is currently active
Code: Select all
#If WinActive("ahk_pid " DllCall("GetCurrentProcessId"))
... ; here goes your code, which would get executed only if any of script's windows is currently active
Don't use "ahk_id " WinExist() unless you actually want to restrict it to the first matching window.