Jump to content
Sign in to follow this  
johond

winwaitactive on not predictable window

Recommended Posts

johond

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 ?

Share this post


Link to post
Share on other sites
Gigglestick

Change

if winwaitactive("example") then

to

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

to wait 5 seconds, then continue.

Or, check into AdLibEnable if you need to do other things while waiting for this window to appear.

Edit: nunya!

Edited by c0deWorm

My UDFs: ExitCodes

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Gigglestick

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Gigglestick

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

Share this post


Link to post
Share on other sites
JSThePatriot

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)

Share this post


Link to post
Share on other sites
Gigglestick

Yes, WinExists and ControlSend are my preference also, but I stuck to WinActive and Send since the poster asked it that way.

Nice catch, JSThePatriot.


My UDFs: ExitCodes

Share this post


Link to post
Share on other sites
Gigglestick

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

Share this post


Link to post
Share on other sites
JSThePatriot

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)

Share this post


Link to post
Share on other sites
Gigglestick

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

Yeah, your code was right if you want to do something while you're waiting. :whistle:

My UDFs: ExitCodes

Share this post


Link to post
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
Sign in to follow this  

×