Sign in to follow this  
Followers 0
Link8

How to prevent application from stealing focus?

6 posts in this topic

Is there any way to prevent annoying application from stealing focus from user? I have searched many forums and didn't find solution. I have the application in which I need to make 1 operation each 30 minutes. The operation takes 5 minutes. After it's completed it display OK window which states that operation was completed successfully. I do not care about this and do not want to steal focus from me.

Since Windows is unable to do this the only one solution for me is that some script will check active window every 0.1 second and if it see that the active window became the window with OK button it press Alt+Shift+Tab to revert to my application. May be there are some more clever solutions and that will be very good.

I use Windows 7.

Share this post


Link to post
Share on other sites



What about something like this?

Local $MainForm = "Main Title"
Local $AnnoyingForm = "Annoying Title"
While 1
 WinWaitActive($AnnoyingForm)
 ControlClick($AnnoyingForm, "", "Button1")
 WinActivate($MainForm)
WEnd

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you for reply.

I think it's better to use key combination ALT+SHIFT-TAB to return you to previous window than MainForm variable, because you can work in different programs, while annoying window will appear.

ALT+SHIFT-TAB = Send("!+{TAB}")

I has written this script based on yours

Local $AnnoyingForm = "Attention!"
While 1
WinWaitActive($AnnoyingForm)
Send("{Enter}")
Send("!+{TAB}")
WEnd

But there are 2 problems.

First that defining the window by name might be dangerous. It might be dangerous to press Enter on any window called Attention!. So is there some way to more closely define the window? Can we use for example a couple of parameters, for example: executable name, the text in this windows, the size of the window. I think "the text in the window" and executable name will be enough.

Another problem is if you write something in web form the script will not return to web form, because there can be many forms on 1 page. So if you write some text in the web form and the window Attention! appear while your are typing something - and the script returns you to main page you will not be able to continue to type in the same web form.

P.S. However we can not press Enter, just press Alt-Shift-Tab. We can always press enter on all Attention! window later. So I think I will remove pressing Enter from script.

Edited by Link8

Share this post


Link to post
Share on other sites

Solution with not pressing Enter doesn't work, because I can not activate this window when script is running to press OK manually. The script return me to previous window.

So I need to figure out how to use a couple of parameters to identify window, for example: executable name, the text in this window, the size of the window. I think "the text in the window" and executable name will be enough.

Share this post


Link to post
Share on other sites

I figure out that we do not need ALT+SHIFT+TAB, but we need ALT+TAB, because first is return to the oldest window, second is to return to newest window.

ALT+TAB = ("!{TAB}")

Now the script looks like this:

Local $AnnoyingForm = "Внимание!"
While 1
WinWaitActive($AnnoyingForm)
Send("{Enter}")
Send("!{TAB}")
WEnd

Please help me to figure out how to use several parameters to determine window on which action needed to be done. I need not only use windows name, but text in window and executable name.

Share this post


Link to post
Share on other sites

If you use shell hooking then HSHELL_WINDOWACTIVATED will tell you when a window takes the focus and what the handle to that window is, so you can then set focus back to your window.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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