Jump to content
Sign in to follow this  

Detect Desktop Focus

Recommended Posts


Im trying to get a script to not execute a portion of code if the desktop is in active focus. I have used the following code with no luck. Any help is greatly appreciated. Thank you!

For this example if notepad.exe was executed, it should focus on the Untitled window and hide it. It should then set the focus back to the previous application unless the desktop was the current active window.

WinWaitActive("Untitled -")

WinSetState("Untitled -", "", @SW_HIDE)

If Not WinActive("Program Manager", "") Then

Send("{ALT DOWN}")


Send("{ALT UP}")


Share this post

Link to post
Share on other sites

WinActive("Program Manager", "") method works fine.

As for your code snippet, keep in mind that even after you hide that Notepad window, it's still active. To make desktop active you'd have to click on it. Therefore your code always executes ALT-TAB.

Edited by Siao

"be smart, drink your wine"

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.