Permanent Focus

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Permanent Focus

Post by JRL » Mon Mar 21, 2011 3:16 pm

Is there any way to have a HardFocus system variable or function? A method that would, in essence, FORCE each ensuing line of code to be applied to the specified window until the variable is set to zero or a StopHardFocus command is issued.

BlockInput allows us to control user interference but every now and then a script fails to place the keystroke or mouse click on the proper window because some other application automatically spawns some "helpful" window. For example, Microsoft, Firefox, Adobe, Java all have automatic updates. They might not actually run but might simply place an icon in the taskbar and that icon placement can steal focus from the script.

Hmmmmm. Thinking and typing. Just occurred to me that perhaps there's a way to stop this problem using the Window_Newactive OnEvent>. The only way I can think to test it is to put it in a script and wait to see if the script stops failing. This could take a while.

I'm going to post this just to give some future reader the insight that their script might be failing when an automatic update steals focus from their script. Any one else have any thoughts on this subject?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Mar 21, 2011 9:26 pm

The following script seems to prove OnEvent>WINDOW_NEWACTIVE will do what I need. This sample starts Notepad then counts to 100 placing the count as separate lines of text on the notepad screen.

While this was running on my computer I clicked around the desktop opening different windows. I have run this multiple times and not had any text not sent to notepad when I stuck to opening other windows with a mouse click on the desktop. You can make this fail by pressing keys or picking on the notepad window but the goal wasn't to make a foolproof system, the goal was to find a method that will prevent auto-opening windows from interfering with my scripts by stealing focus.

Hope that someone finds this useful.

Code: Select all

Run>Notepad.exe
WaitWindowOpen>NotePad*
Wait>0.5
SetFocus>Notepad*
OnEvent>WINDOW_NEWACTIVE,0,0,RefocusNotePad
Let>Start=0
Repeat>Start
  Add>Start,1
  GoSub>Dwell,20
  Send>Start
  Press Enter
Until>Start=100

SRT>RefocusNotePad
  SetFocus>NotePad*
END>RefocusNotePad

SRT>Dwell
  Let>DwellCount=0
  Repeat>DwellCount
    Add>DwellCount,1
    Wait>0.01
  Until>DwellCount=%Dwell_var_1%
END>Dwell

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts