Finding Relative Position of Cursor?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
4Blades
Newbie
Posts: 2
Joined: Wed Jul 20, 2011 3:53 pm

Finding Relative Position of Cursor?

Post by 4Blades » Wed Jul 20, 2011 9:21 pm

Hi,
Newb here, obviously.
I'm trying to make a macro that will work on anyone's screen, at any window size for a given program.

I need the macro to click on a red button (using the findcolor function to find it), then click on another red button that is always the same relative distance from red button 1.

But I notice that there is no function for finding the relative position of a mouse pointer...only a function to move it a relative distance. Which is odd, because the editor itself can show relative position, but there is no function for it?

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

Post by JRL » Thu Jul 21, 2011 3:20 am

But I notice that there is no function for finding the relative position of a mouse pointer...
In order fro a position to be relative, it needs to be related to something else. The "Relative" setting in the editor displays the current cursor position relative to the screen coordinates of the zero point of the current active window. Its true there is no built in function to display the relative cursor coordinates but its an easy calculation based on GetActiveWindow and GetCursorPos. The following will produce the same result as the Editor's relative mouse position setting.

Code: Select all

GetActiveWindow>WinTitle,WinX,WinY
GetCursorPos>CurX,CurY
Let>RelPosX=%WinX%-%CurX%
Let>RelPosY=%WinY%-%CurY%
You can treat the coordinates returned by the findcolor function similarly. Once you have the X/Y posion of the first red button, Just add the relative distance onto those coordinates, move the mouse there and click.

4Blades
Newbie
Posts: 2
Joined: Wed Jul 20, 2011 3:53 pm

Post by 4Blades » Thu Jul 21, 2011 7:27 pm

Ah. Nice. Thanks!

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