Jump to content

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


Recommended Posts

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...

Link to comment
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.

Link to comment
Share on other sites

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...

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...