Jump to content

Prevent new window from taking focus


Recommended Posts

TL;DR: I'm looking for a way to prevent specific newly created (not created via autoit) windows from stealing focus (or from showing at all if possible) for the split second it takes for the script to automate them.

About once a week I have to print a bunch of pages, 1 at a time, to a PDF printer. I already have the process scripted and it takes about 30 minutes so normally I just turn it on and go to lunch. I'm trying to modify the script so the whole process runs in the background and I can keep using my computer without interruption. The script already uses all Control...() functions so none of the windows need to have focus to work. But, every minute or so, a couple windows pop up (print dialog, pdf program, save as dialog, etc) stealing the focus for a split second which can interrupt my typing/mouse clicking in other windows. That's what I'm trying to fix.

I figure I need to hook the window creation event somehow as I need to interrupt the process before the window gets displayed. I've tried the hooking example from '?do=embed' frameborder='0' data-embedContent>> and using WinSetState(..., @SW_HIDE) but the window still appears and steals focus for a brief moment.

Basically, the code looks like this:

while true

press print

wait for print dialog

press ok

wait for pdf dialog

press save

wait for save as dialog

fill in file name

press ok

go to next page

wend

I'd like to do something like:

register that the print dialog is about to open

press print

event handler fires from registered print dialog opening and doesn't allow it to take focus

unregister print dialog

press ok

etc...

Any help would be appreciated.

Edited by BurninSun
Link to comment
Share on other sites

That's a good one.  I'm not sure. Perhaps you can WinSetOnTop on the other windows you are interacting with.

Although just because something it always on top doesnt mean focus... Maybe that something you can test and see if it works for you.

Link to comment
Share on other sites

If I understand you want the whole process to run in the background

and be able to work on something else without being interupted.

Could you use @SW_HIDE to hide the anoying popups.

Post your script to give a better Idea of what your doing.

Edited by trashy
Link to comment
Share on other sites

Here is a snippet of the code. Most of it is somewhat unreadable because it references controls on various programs that won't make sense without seeing those programs running

ControlClick("Print", "What to print", "[CLASS:Button; INSTANCE:6]") ; print setup, ok button
  WinWait("Print", "Printer")
  ControlClick("Print", "Printer", "[CLASS:Button; INSTANCE:10]") ; standard print dialog, ok button
  WinWait("PDFCreator")
  ControlClick("PDFCreator", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:7]") ; pdfcreator, save button
  WinWait("Save as")
  ControlSetText("Save as", "", "[CLASS:Edit; INSTANCE:1]", $name[0]) ; standard save as dialog, fill in filename
  ControlClick("Save as", "", "[CLASS:Button; INSTANCE:2]") ; standard save as dialog, ok button

Using WinSetOnTop helps a bit visually but you're correct in that it doesn't stop focus stealing.

@SW_HIDE is what I've been looking into, but I'm not using Run() or ShellExecute(), so I can't hide it from the start. At best, I can detect the creation of the window using shell hooks then use WinSetState to hide it, but it still takes focus for a split second. My hope was to use a shell hook on window creation to call WinSetState with @SW_HIDE before the window activation event. So far, even though I have the hooks, it seems autoit's hook won't run until after the window is activated.

Edited by BurninSun
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...