SetFocus problem

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

SetFocus problem

Post by RNIB » Fri Mar 13, 2009 2:41 pm

I'm trying to write a macro that ammends data within an application we use which involves accurately switching between different windows in this application and that's where I have a problem that I can't figure out a solution for.

There is one window that we constantly have to go in and out of which is called the Table of Contents editor which consists of 4 different tabs. However no matter what tab you select the title of the window remains the same.

This is the window in question:
Image

In this screen grab everything is as I want it to be, the window has focus and the heading (page 45 in this exampel) is highlighted in blue.

Sometimes however when Macro Scheduler sets focus on this window, it looks like this:

Image
What's happened here is that focus is actually on the Pages tab itself (see the outline around the word pages).

This is causing me a lot of problems because the next thing to do is to rename that page by pressing F2. If the page is correctly highlighted as per the first screen grab I only need to press F2. However if it's like the 2nd screen grab then I need to press Tab and then press F2.

Is there a way I can either detect the colour of the highlighted area and if it's not blue then to press Tab first or to simply make sure that when focus is set on the window its set on the contents of the tab rather than the tab itself?

Just in case this has any impact on what solutions I could use the contents of this window will change, the highlighted section will change each time the macro is run (the macro will be set to loop), I'd rather not use x,y co-ordinates to simply perform a left click in the box because this window could be anywhere on the screen and the amount of text shown in that window will vary and affect where on the screen you could click.

Hope that makes sense!

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: SetFocus problem

Post by jpuziano » Fri Mar 13, 2009 3:46 pm

Hi RNIB,
RNIB wrote:If the page is correctly highlighted as per the first screen grab I only need to press F2. However if it's like the 2nd screen grab then I need to press Tab and then press F2.
If there will only ever be one of these windows on the screen at any one time, then you could make use of image recognition.

Use the Image Capture Tool in MS to capture an image of that Page tab including the dashed lines around it. Those dashed lines indicate it has focus.

Use the FindImagePos> command to look for that needle image in the screen.

- if you find it, the Page tab has focus, send Tab then F2
- if you don't find it, the Page tab does not have focus, send only F2

Just a thought... let us know how it works for you.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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