Jump to content

winwaitactive on not predictable window


 Share

Recommended Posts

Hi, im trying to write a script to configure a software. But there is a window that can or cannot popup, I know when this event can happen so I wrote something like this:

if winwaitactive("example") then

send("{SPACE}")

othercode

but it doesn't work..

...

any hint ?

Link to comment
Share on other sites

  • Moderators

If WinExists("EXAMPLE") Then
     Send("{SPACE}")
    ; Rest of script
EndIf

Or

If WinActive("EXAMPLE") Then
     Send("{SPACE}")
    ; Rest of script
Else
   WinWaitActive("EXAMPLE", "", 5)
     If WinActive("EXAMPLE") Then
            Send("{SPACE}")
           ; Rest of script
     EndIf
EndIf

Wouldn't that work?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If WinActive("EXAMPLE") Then
     Send("{SPACE}")
  ; Rest of script
Else
   WinWaitActive("EXAMPLE", "", 5)
     If WinActive("EXAMPLE") Then
            Send("{SPACE}")
          ; Rest of script
     EndIf
EndIf

Wouldn't that work?

That's redundant. WinWaitActive works exactly like WinActive if they window is already active: it returns immediately. If not, it waits until the window is active or the time runs out.

You don't need to test it twice, much less three times.

If WinWaitActive("example", "", 5) Then
    Send("{SPACE}")
EndIf

Edit: Added code sample response.

Edited by c0deWorm

My UDFs: ExitCodes

Link to comment
Share on other sites

  • Moderators

So your saying that:

If WinWaitActive("example", "", 5) Then

Is correct the syntax?

Edit: I'm talking about syntax, and I can't spell :whistle:

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

You're right about testing it 3 times... :dance::whistle:

And it works with the way you posted... It just never looked right doing it that way... But you learn something every day :dance: GJ.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

So your saying that:

Is correct the syntax?

Edit:  I'm talking about syntax, and I can't spell :whistle:

Yes, the syntax is correct. It will return 1 if the window becomes active during the wait, or zero if the timeout occurs.

Might want to use this with it if you don't know the exact title:

Opt("WinTitleMatchMode", 2)

My UDFs: ExitCodes

Link to comment
Share on other sites

Here is a snippet of code I used recently to check for popup windows that may or may not pop up. (I generally had a time frame in which they would pop up).

While 1
        If WinExists("tim") Then
            ControlClick("tim", "", 1027)
        Else
            Sleep(500)
            $count += 1
        EndIf
        If $count = 8 Then
            ExitLoop
        EndIf
    WEnd

The above code (+=) requires the beta to work properly.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

While 1
        If WinExists("tim") Then
            ControlClick("tim", "", 1027)
        Else
            Sleep(500)
            $count += 1
        EndIf
        If $count = 8 Then
            ExitLoop
        EndIf
    WEnd
WinWait does exactly what your snippet does. Simplify that to:

If WinWait("tim", "", 4) Then
    ControlClick("tim", "", 1027)
EndIf

My UDFs: ExitCodes

Link to comment
Share on other sites

WinWait does exactly what your snippet does.  Simplify that to:

If WinWait("tim", "", 4) Then
    ControlClick("tim", "", 1027)
EndIf

<{POST_SNAPBACK}>

True, except the reason I performed the operation the way I did, is to also allow (in the future) to display a progress bar.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...