How Do I Get the Mouse Position Relative to the Front Window

Is there a way to get the mouse position relative to the front window?


will find the absolute position only, right?

you can take the value of the front Window width, subtract the width of the Screen, and add the Mouse position, ie

WinFrame.Width - SCREENVISIBLE(Main,Width) + MOUSEX()


Well that's clever- thanks!

1 Like

I'd like the pink action to save the mouse location relative to the front window and the green ones to recall it, even if the window moves. How can I use your suggestion to achieve this? As you can see, it currently only works with absolute position.


Interesting, let me think about it.
For that you'd need two additional fields, ie Front Window's X and Y to be updated before running the subsequent actions

1 Like

Yes, that makes sense. So I'm guessing it would be:

Get front window corner coordinates A
Get mouse coordinates A
Get front window corner coordinates B
Mouse coordinates + (corner coordinates B minus A) = mouse coordinates B
Move mouse to mouse coordinates B
Click mouse

I just need to figure out how to get the front window corner coordinates and how to do the calculation.

For that you use %WindowFrame%,
ie %WindowFrame%1%

or %FrontWindowPosition% if you just need the Top Left coordinates, it outputs something like: "472, 25".

Maybe this:


you'll need to update WinFrameTest every time you move the front window

1 Like

I often need to perform those calculations too. It might be handy if KM had a function that returned this without us having to do those calculations. Or better yet, it would be fabulous if KM allowed macros to return values like functions so that we could solve problems like this ourselves.

1 Like