Sign in to follow this  
Followers 0
callagga

WinActive() - is only 1 window active at any one time?

5 posts in this topic

Hi,

is only 1 window active at any one time? Ie with multiple apps running & some apps that have multiple windows, there is only one out of all these that will be active?

does "active" = has the focus?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes to both questions.

The window with the focus (even if not in front) is the active window and only one window can have the focus at a time. It is possible for no window to have the focus, but that is a pretty useless condition and pretty easy to change.

Just because a window is not considered active does not mean that the program associated with that window is not running or even accepting events, nor does it mean that the window might not be displayed while not active. It just means that the active window has the focus.

Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

@callagga,

You can get many answers with a simple If...Then and a MsgBox().

If WinActive("window") Then MsgBox(64,"Success!","There is only one window active at a time!")

Share this post


Link to post
Share on other sites

thanks - what I'm struggling with is, when I've sent keys in Window 1, and then want to move on to Window 2 (i.e. close window 1 first), how to validate in my code this has occured, so it's not possible the script can start sending Window2 keys to Window1 because there was some issue closing it..

I guess specifically can I ask:

a) if I send a control-s to a window that triggers a save/close for that app, how can I check this worked? In the case of the application I'm working it does seem to keep this Window active, but NOT VISIBLE, I guess to reuse later (this is my little gottcha for the question)

>_< to be sure that things are ready for you to send characters, but also want to minimise script delays (i.e. and avoid using Sleeps) which funtions should I use? Eg Winwaitactive()? , WinWaitActive() followed by ControlGetFocus() check? That is, what's best practice here to avoid ever having to worry about a need to use Sleeps.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Check the documentation for SendKeepActive and ControlSend for some ideas on sending keys to a given window or control. Check WinExists or WinActive in a decision structure to see of a window is closed. WinActivate will give the focus to a window.

WinClose("Window 1")
While WinExists("Window 1")
    Sleep(250) ; Wait 1/4 second before checking again.
Wend
; At this point "Window 1" has been closed.
WinActivate("Window 2")
SendKeepActive("Window 2", "Test text ^s")
Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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  
Followers 0