WinWaitClose prevents other timer?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kashmirLZ
Posts: 53
Joined: 06 Oct 2022, 23:27

WinWaitClose prevents other timer?

13 May 2024, 10:23

oi m8 whats the big idea here?
i wanna run 2 timers but using either Sleep or WinWaitClose causes timer "one" here to not a chance to run at all :|

1. what's going on?
2. what's the workaround?

Code: Select all

one(){
    ToolTipTimer("one")
    Sleep 3000
    i := 0
    Loop {
        ToolTipTimer(i)
        Sleep 500
        i++
    } Until (i == 20)
}

two() {
    ToolTipTimer("two")
    Sleep 1000
    ToolTipTimer("waiting calc close")
    WinWaitClose Calculator
    ToolTipTimer("calc closed")
}

SetTimer, one, 1000
SetTimer, two, 2000
Rohwedder
Posts: 7719
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinWaitClose prevents other timer?

13 May 2024, 11:17

Hallo,
in your timer one() is a sleep 3000 i.e. 3 seconds.
With SetTimer, one, 1000 you demand that the script should sleep for three seconds every second?
Do you manage to sleep 72 hours every day?
A script cannot do several things at the same time! It cannot sleep (Sleep) and wait for a window to close (WinWaitClose) at the same time.
Describe in words what you actually want!
kashmirLZ
Posts: 53
Joined: 06 Oct 2022, 23:27

Re: WinWaitClose prevents other timer?

19 May 2024, 00:08

Rohwedder wrote:
13 May 2024, 11:17
With SetTimer, one, 1000 you demand that the script should sleep for three seconds every second?
Actually in AHK, if you Sleep within a Timer, it will simply delay the execution of the next timer.
So no, it's not possible to "sleep for three seconds every second" :)
Rohwedder
Posts: 7719
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinWaitClose prevents other timer?

19 May 2024, 01:49

two() is called during the runtime of one() and thus blocked one().
Try these with and without Critical:

Code: Select all

#Persistent
DetectHiddenWindows, On
one() {
	Critical ; <<<
	SoundBeep, 4000, 20
}
two() {
	SoundBeep, 1000, 20
	WinWaitClose, ahk_id %A_ScriptHwnd%
}
SetTimer, one, 1000
SetTimer, two, 2000

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 117 guests