SetFocus

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

SetFocus

Post by hagchr » Fri Jul 17, 2015 12:53 pm

I used the Code Builder to insert "SetFocus>" in a script. I selected the RegEx option so it looked like this:

Let>WIN_REGEX=1
SetFocus>Skype

Alone in a script this works fine. However, in my script it did not focus consistently. Then I realized that I had used "Window Handles" earlier in the script:

Let>WIN_USEHANDLE=1
GetActiveWindow>tmp,nXPos,nYPos,,

If I understand it correctly then both the RegEx and the Window Handles options were active at the same time(conflict??). So then I added a line before "SetFocus" where I turn off the "Window Handles" and then it seems to work fine.

Let>WIN_USEHANDLE=0
Let>WIN_REGEX=1
SetFocus>Skype

Is my understanding correct that when you eg use Code Builder and change "mode" you may have to turn off any old ones "manually" to avoid conflicts?

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: SetFocus

Post by hagchr » Fri Jul 17, 2015 8:20 pm

Did some more thinking and I think it is clear to me now.

The systems variables start off at default values and stay unchanged until changed (or end), ie in my case "using Window Handles" is active also later in the program. By using "SetFocus" with RegEx selected it was actually trying to match a Window Handle, ie a number and not the title, therefore no match. By turning "using Window Handles" off it matched the window title instead and everything was fine.

Conclusion, one needs to be careful when changing systems variables as there could be impacts in other (easy to forget) places.

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