Is there a cleaner way to use WinWait / IfWinNotActive without repeating it?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Cardano ADA
Posts: 8
Joined: 11 Jan 2022, 01:14

Is there a cleaner way to use WinWait / IfWinNotActive without repeating it?

Post by Cardano ADA » 11 Jan 2022, 06:10

Is there a better way to use the

Code: Select all

WinWait
if not

Code: Select all

IfWinNotActive
, code where I can have it check before each click instead of having it repeat the command over and over?

Code: Select all

WinWait, My Dashboard — Mozilla Firefox
IfWinNotActive, My Dashboard — Mozilla Firefox, , WinActivate, My Dashboard — Mozilla Firefox, 
WinWaitActive, My Dashboard — Mozilla Firefox,

MouseClick, left,  1009,  315 


WinWait, My Dashboard — Mozilla Firefox
IfWinNotActive, My Dashboard — Mozilla Firefox, , WinActivate, My Dashboard — Mozilla Firefox, 
WinWaitActive, My Dashboard — Mozilla Firefox,

MouseClick, left,  1009,  436 


WinWait, My Dashboard — Mozilla Firefox
IfWinNotActive, My Dashboard — Mozilla Firefox, , WinActivate, My Dashboard — Mozilla Firefox, 
WinWaitActive, My Dashboard — Mozilla Firefox,

MouseClick, left,  1009,  500

Rohwedder
Posts: 7683
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Is there a cleaner way to use WinWait / IfWinNotActive without repeating it?

Post by Rohwedder » 11 Jan 2022, 10:12

Hallo,
https://www.autohotkey.com/docs/misc/WinTitle.htm#LastFoundWindow
Try:

Code: Select all

WinWaitActive, My Dashboard — Mozilla Firefox
MouseClick, left,  1009,  315
WinWaitActive
MouseClick, left,  1009,  436
WinWaitActive
MouseClick, left,  1009,  500

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Is there a cleaner way to use WinWait / IfWinNotActive without repeating it?

Post by Xtra » 11 Jan 2022, 12:56

Another example using a function:

Code: Select all

WaitClick(1009, 315)
WaitClick(1009, 436)
WaitClick(1009, 500)

WaitClick(x, y, wintitle := "My Dashboard — Mozilla Firefox")
{
    WinWait, % wintitle
    WinActivate, % wintitle
    WinWaitActive, % wintitle
    MouseClick, left, x, y
}


Post Reply

Return to “Ask for Help (v1)”