How count pixels to place the cursor properly?

Newbie question. I’m writing a macro that must click in precise locations on a window in order to activate the correct parts of a program. For example, I need to fill in a certain dialog box.

The correct command is Move and Click at (x,y) from the Front Window.
But, is there a way to figure out x and y without just trial and error? For example, here is a program to measure screen locations, but it’s $10. http://www.ondesoft.com/rulers/pixel-ruler.html
I have a retina display - I’m not sure if that matters.
thanks for any advice.

Hey Reegor,

There's a freebie.

https://www.macupdate.com/app/mac/40403/mousecoord

It's a little awkward to use, but it works.

However the best way to go about this is to use Keyboard Maestro itself to get the coordinates, because you're certain to get values that KM understands.

Watch out for tooltips though. They can pop up unexpectedly and throw the calculation off.

-Chris


Mouse { Coordinates }.kmmacros.zip (1.3 KB)

Cool! I extended and altered little bit...

Screen: → %Calculate%MOUSEX()% / ↓ %Calculate%MOUSEY()% / ← %Calculate%MOUSEX()-SCREEN(1,Right)% / ↑ %Calculate%MOUSEY() - SCREEN(1, Bottom)%
Window: → %Calculate%MOUSEX()-WINDOW(1,Left)% / ↓ %Calculate%MOUSEY()-WINDOW(1,Top)% / ← %Calculate%MOUSEX()-WINDOW(1,Right)% / ↑ %Calculate%MOUSEY()-WINDOW(1,Bottom)%

From Last Check: → %Calculate%MOUSEX() - lastMouseCheckX% / ↓ %Calculate%MOUSEY() - lastMouseCheckY%
[Note: This is relative to Top, Left as 0, 0 - so a ↓ that is negative is up and a → that is negative is left].

Sample Output

Screen: → 1331 / ↓ 455 / ← -717 / ↑ -825
Window: → 1331 / ↓ 433 / ← -717 / ↑ -821

From Last Check: → -73 / ↓ -259
[Note: This is relative to Top, Left as 0, 0 - so a ↓ that is negative is up and a → that is negative is left].

Now it reports X,Y relative to foremost screen as well. The last bit in there shows you the relative position of mouse since the last time you triggered the macro (which is useful if you have a macro where the next step is relative to the last one). It requires creating a couple of variables (which I labeled lastMouseCheckX and lastMouseCheckY).
I do note that Bottom Left Window does not report the same thing as Bottom Left Screen - which I would expect if an app is maximized (its dif by 4 pixels) - I did not dig in to troubleshoot.