How to Winwait for two windows simultaneously in AutoIt? How to Winwait for two windows simultaneously in AutoIt? windows windows

How to Winwait for two windows simultaneously in AutoIt?


A simpler solution might be to use a REGEX title in your WinWaitActive as defined here

You would then have something like this:

$hWnd = WinWaitActive("[REGEXPTITLE:(WindowWithThisTitle|WindowWithThatTitle)]")If WinGetTitle($hWnd) = "WindowWithThisTitle" then    DoSomething()Else    DoSomethingElse()EndIf


How about something like this.

$stillLooking = TrueWhile $stillLooking    $activeWindowTitle = WinGetTitle(WinActive(""))    If $activeWindowTitle == "Title1" Then        MsgBox(0, "", "Do something")        $stillLooking = False    ElseIf $activeWindowTitle == "Title2" Then        MsgBox(0, "", "Do something else")        $stillLooking = False    EndIf    sleep(5)WEnd

Because I don't want to have thetimeout which could be more than 15seconds.

WinWaitActive() doesn't have a timeout unless you specify one. You gave it a five second timeout but you could leave that off and it would wait forever.


You can use this Functions for two windows ..

; #FUNCTION# ====================================================================================================================; Name...........: _2WinWait; Description ...: Wait For Tow Windows .; Syntax.........: _2WinWait ($FirstTitle,$SecondTitle,[$FirstText = "" ,[$SecondText = ""]] ); Parameters ....: $FirstTitle  - Title Of First  Wondow ;                  $SecondTitle - Title Of Second Wondow ;                  $FirstText   - Text  Of First  Wondow ;                  $SecondText  - Text  Of Second Wondow ; Return values .: Success - None;                  Failure - Returns a 0 => If Your Titles Is Wrong; Author ........: Ashalshaikh : Ahmad Alshaikh; Remarks .......: ; Related .......:; Link ..........;; Example .......; No; ===============================================================================================================================Func _2WinWait ($FirstTitle,$SecondTitle,$FirstText = "" ,$SecondText = "" )    If $FirstTitle = "" Or $SecondTitle = "" Then        Return 0     Else        Do         Until WinExists ($FirstTitle,$FirstText) Or WinExists ($SecondTitle,$SecondText)    EndIfEndFunc; #FUNCTION# ====================================================================================================================; Name...........: _2WinWait_Any ; Description ...: Wait For Tow Windows And Return Any Window Id Exists .; Syntax.........: _2WinWait_Any ($FirstTitle,$SecondTitle,[$FirstText = "" ,[$SecondText = ""]] ); Parameters ....: $FirstTitle  - Title Of First  Wondow ;                  $SecondTitle - Title Of Second Wondow ;                  $FirstText   - Text  Of First  Wondow ;                  $SecondText  - Text  Of Second Wondow ; Return values .: Success - Number Of Window ==> 1= First Window , 2= Second Window;                  Failure - Returns a 0 => If Your Titles Is Wrong; Author ........: Ashalshaikh : Ahmad Alshaikh; Remarks .......: ; Related .......:; Link ..........;; Example .......; No; ===============================================================================================================================Func _2WinWait_Any ($FirstTitle,$SecondTitle,$FirstText = "" ,$SecondText = "" )    If $FirstTitle = "" Or $SecondTitle = "" Then        Return 0     Else        Do         Until WinExists ($FirstTitle,$FirstText) Or WinExists ($SecondTitle,$SecondText)        If WinExists ($FirstTitle,$FirstTexit) Then             Return 1         Else            Return 2         EndIf    EndIfEndFunc

for more with examples