Auto-Suspend script when any program from list is active

Post your working scripts, libraries and tools for AHK v1.1 and older
infearno
Posts: 2
Joined: 28 Feb 2022, 02:22

Auto-Suspend script when any program from list is active

28 Feb 2022, 02:34

Hello everyone!
Please help me to solve this riddle...

My goal is: Suspend script when any program from the list is active (WinActive) or exists (WinExist) and stay suspended untill program is active|exists
Why: Some games need to use buttons I use in everyday life.

I searched forum for solution. Found several solutions for one program. If I reuse those (like copy code for each program - they will start to conflict)

My incomplete solutions:
1. This one has an issue - it unsuspends in each loop when app is not an active one.

Code: Select all

SuspendOnActiveGame:

ProgramList := ["DOOMEternalx64vk.exe", "sw.x64.exe", "Hades.exe","Dishonored.exe","Dishonored2.exe","Deathloop.exe","DaysGone.exe","HorizonZeroDawn.exe","DyingLightGame_x64_rwdi.exe"]

MaxindexProgramList := ProgramList.MaxIndex()
CurrentIndexProgramList := 1
WindowExists := False

While(CurrentIndexProgramList <= MaxindexProgramList) {
    ConcatElement := "ahk_exe " . ProgramList[CurrentIndexProgramList]
    If WinActive(ConcatElement) and (!A_IsSuspended)
	    Suspend, On
    If !WinActive(ConcatElement) and (A_IsSuspended)
	    Suspend, Off
    CurrentIndexProgramList++
}
return
2. This code is inserted instead of while loop in 1. Here I tried to "lock" suspend-decision to last loop. Just don't work. Always stays unsuspended.

Code: Select all

While(CurrentIndexProgramList <= MaxindexProgramList) {
    ConcatElement := "ahk_exe " . ProgramList[CurrentIndexProgramList]
    if WinExist(ConcatElement)
        WindowExists := True
    if !WinExist(ConcatElement) and (!WindowExists)
        WindowExists := False
    if (CurrentIndexProgramList == MaxindexProgramList) and (WindowExists) and (!A_IsSuspended)
        Suspend, On
    if (CurrentIndexProgramList == MaxindexProgramList) and (!WindowExists) and (!A_IsSuspended)
        Suspend, Off
}
return
infearno
Posts: 2
Joined: 28 Feb 2022, 02:22

Re: Auto-Suspend script when any program from list is active

28 Feb 2022, 07:32

Found this solution. If anybody has better one - please.

Code: Select all

SetTimer, SuspendOnActiveGame, 500

SuspendOnActiveGame:

ProgramList := ["DOOMEternalx64vk.exe", "sw.x64.exe", "Hades.exe","Dishonored.exe","Dishonored2.exe","Deathloop.exe","DaysGone.exe","HorizonZeroDawn.exe","DyingLightGame_x64_rwdi.exe"]

MaxindexProgramList := ProgramList.MaxIndex()
CurrentIndexProgramList := 1
WindowExists := False


While(CurrentIndexProgramList <= MaxindexProgramList) {
    ConcatElement := "ahk_exe " . ProgramList[CurrentIndexProgramList]
    If WinActive(ConcatElement)
        WindowActive := True
    CurrentIndexProgramList++
}
if WindowActive and (!A_IsSuspended)
    Suspend, On
if !WindowActive and (A_IsSuspended)
    Suspend, Off
return
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Auto-Suspend script when any program from list is active

24 Aug 2022, 13:15

infearno wrote:
28 Feb 2022, 07:32
Found this solution. If anybody has better one - please.

Code: Select all

SetTimer, SuspendOnActiveGame, 500

SuspendOnActiveGame:

ProgramList := ["DOOMEternalx64vk.exe", "sw.x64.exe", "Hades.exe","Dishonored.exe","Dishonored2.exe","Deathloop.exe","DaysGone.exe","HorizonZeroDawn.exe","DyingLightGame_x64_rwdi.exe"]

MaxindexProgramList := ProgramList.MaxIndex()
CurrentIndexProgramList := 1
WindowExists := False


While(CurrentIndexProgramList <= MaxindexProgramList) {
    ConcatElement := "ahk_exe " . ProgramList[CurrentIndexProgramList]
    If WinActive(ConcatElement)
        WindowActive := True
    CurrentIndexProgramList++
}
if WindowActive and (!A_IsSuspended)
    Suspend, On
if !WindowActive and (A_IsSuspended)
    Suspend, Off
return
Did your solution work?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 74 guests