Jump to content

How can I tell which window has focus in AutoIt?


peter1234
 Share

Recommended Posts

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.

Link to comment
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
Link to comment
Share on other sites

  • 13 years later...

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