I wonder if it is possible to check to see if a window has focus in AutoIt. I have checked and not found much. I have tried using WinSetOnTop but this didn't seem to do anything so then I considered using WinActivate but this didn't seem to do what I need.

The reason I want to do this is because I have this application I am writing as a prank and I do not want the co-worker on whom I'm playing the prank to just ignore the window when it starts automatically. I am wanting to put a shortcut to it in the startup folder and we have several applications that run on startup and so I want mine to either always be on top or audibly shout rude words at the user if they try and ignore the application.

Is this possible and, if so, can you help me out because I am out of ideas.

1 Answer

Regardless of your motives, you may try WinWaitActive.

Syntax:

WinWaitActive ( "title" [, "text" [, timeout = 0]] ) 

Example that may be useful to try it out:

Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. WinWaitActive("[CLASS:Notepad]", "", 10) ; Wait for 2 seconds to display the Notepad window. Sleep(2000) ; Close the Notepad window using the classname of Notepad. WinClose("[CLASS:Notepad]") EndFunc ;==>Example 

Reference:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.