Sign in to follow this  
Followers 0
peter1234

How can I tell which window has focus in AutoIt?

4 posts in this topic

Is there anyway in AutoIt to tell which window (GUI) is on top (has focus)? I can set the focus in AutoIt, but there does not seem to be any way to detect when the user has changed focus.

It is possible to check for mouse clicks and check where the mouse was located when it was clicked, but this does not work when working with transparent regions because the Windows operating system can look through the transparent part of the region and set focus to what is under the region where the mouse was clicked. Also focus can be changed by clicking program in the task bar.

I am writing some functions to drag transparent regions. When one transparent region is on top of another I can detect that mouse was clicked over the regions, but I need to know which window is on top in order to know which window to drag. It is not possible to keep track of which window is on top in the script because it is not possible to detect which region was clicked when one transparent region is on top of aother.

Share this post


Link to post
Share on other sites



Is there anyway in AutoIt to tell which window (GUI) is on top (has focus)? I can set the focus in AutoIt, but there does not seem to be any way to detect when the user has changed focus.

It is possible to check for mouse clicks and check where the mouse was located when it was clicked, but this does not work when working with transparent regions because the Windows operating system can look through the transparent part of the region and set focus to what is under the region where the mouse was clicked. Also focus can be changed by clicking program in the task bar.

I am writing some functions to drag transparent regions. When one transparent region is on top of another I can detect that mouse was clicked over the regions, but I need to know which window is on top in order to know which window to drag. It is not possible to keep track of which window is on top in the script because it is not possible to detect which region was clicked when one transparent region is on top of aother.

you could use WinGetTitle("") to get the windowtile of the currently active window and compare it with the windowtile of your desired window.

e.g.:

#include <misc.au3>

opt("WinTitleMatchMode", 4)

Dim $currentTitle
Dim $lastTitle

While Not _isPressed ("1B")
    $currentTitle = WinGetTitle("active")
    If $currentTitle <> $lastTitle And $currentTitle <> "" Then
        FileWriteLine(@ScriptDir & "\instructions.txt", WinGetTitle("active"))
        $lastTitle = $currentTitle
    EndIf
WEnd

Share this post


Link to post
Share on other sites

@jonk:

Great idea. Thanks.

Share this post


Link to post
Share on other sites

@jonk:

Got it working. Thanks again for your help.

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