Correct referencing to window locations

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Marc Lindsay
Newbie
Posts: 8
Joined: Wed Dec 26, 2007 12:33 am

Correct referencing to window locations

Post by Marc Lindsay » Wed Dec 26, 2007 12:56 am

Hi Guys,

New time user here and have a few questions about referencing screen positions and making sure you are always hitting the right co-ordinates, regardless of the end user setup (to a degree)

I will use my lates messings around with screen capturing and image searching, which I am having great success with so far.

Here is the example code (please feel free to suggest a cleaner way of doing the below or any code tips you may have.

Code: Select all

ScreenCapture>1089,252,1211,734,e:\overviewt.bmp
FindImagePos>E:\criteria1.bmp,e:\overviewt.bmp,25,1,X,Y,NumFound
Repeat>NumFound
   Let>X=X_0+1136
  Let>Y=Y_0+252
  MouseMove>X,Y
  LClick
  wait>0.4
 ScreenCapture>1089,252,1211,734,e:\overviewta.bmp
 FindImagePos>E:\criteria2.bmp,e:\overviewta.bmp,25,1,X,Y,NumFoundt

 if>NumFoundt>0
 ScreenCapture>959,155,1211,247,e:\overviewte.bmp
FindImagePos>E:\target.bmp,e:\overviewte.bmp,25,1,X,Y,NumFound1
  Let>X=X_0+959
  Let>Y=Y_0+155
  MouseMove>X,Y
Wait>0.2
  LClick
 endif
Let>NumFound=NumFound-1
ScreenCapture>1089,252,1211,734,e:\overviewt.bmp
FindImagePos>E:\criteria1.bmp,e:\overviewt.bmp,25,1,X,Y,NumFound
Until>NumFound=0
Okay so an explanation of what I am doing first.

Firstly I am searching for said criteria 1 on the screen, when that is found then I am moving to it and clicking on it.

Then I am searching for that click on criteria 1 (the button changes colour) to make sure I have selected the correct one (this is needed as sometimes the position of the button changes between when it is found and when the mouse moves and clicks on it, else I would hit the wrong button).

If it finds that it did indeed select the right item, it then performs the final action (the target.bmp search).

If all goes to plan correctly, then it finishes and does a final search for criteria 1.

It will continue to do this until Criteria 1 is no longer matched.

Now what I would like to be able to do, since as you can see above when it takes a screen capture, using those co-ordinates it is from a full screen.

Can you pass the same commands based on relative position to the active window?

This would make it a much more flexible program, as you can see from above i would only need to manually move my focused window and it would break the macro.

So come on macro guru's show my thy wisdom on this matter as I have tried searching and cannot find it mentioned anywhere?

Also, how do I make sure that my window that I am using always remains focused or on top?

Do I just need to run that into a consistant command in this macro? Or perhaps a seperate macro that keeps the window focused or runs the focus command every 30 seconds or so to make sure nothing interrupts it?

Oh and is there class support or function support creation in MS yet? If not I can see already that being able to create functions would certainly be very very helpfull. That way you could re-use them easily down the track.

If you cannot do this how do you guys get around it currently? Perhaps by tying this in with another programming language?

C# maybe?

Sorry for all the questions just trying to understand MS a bit more :P

Regards
Marc

[/code]

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Dec 26, 2007 8:36 am

Yes, there is in fact a sample macro which captures only the active window. Use GetActiveWindow to get the coordinates and size of the active window. You use these in the ScreenCapture command to get just the window to a bitmap. Use that in FindImagePos. Add the original X,Y coordinates of the window to the found position of the image to convert the found position back to a screen position. One of the sample scripts that comes with the software does exactly this.

Macro Scheduler does not support the concept of classes as it is not an object oriented language. It does support subroutines and there is also the Include command for reusing code in your scripts.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Marc Lindsay
Newbie
Posts: 8
Joined: Wed Dec 26, 2007 12:33 am

Post by Marc Lindsay » Wed Dec 26, 2007 12:07 pm

Thankyou very much,

I will have a play with that then.

Now from what you have said below, that would be a screen cap of the entire window, is it possible to use those co-ordinate from get active window, and then tell screen capture to only capture a selection from within that active window?

If so what would be the easiest way to do this that you know off?

Also did you have any feedback on my code?

Thanks

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