Execute a macro only if mouse is in a specific area on the screen?

Asking because I have a mouse click related macro that helps me highlight text easily.
When activated via mouse click it basically clicks again and holds.
I have configured macro group only for the PDF app. But It seems like the condition just looks if the that app is in front, because if I click on menubar items or dock or some other app not focused but available on same screen it still executes.
So I want to add in an If condition where macro triggers only if mouse is in Right half of screen.


1 Like

Hey @forums2012,

Quite right. The macro group does NOT control where the click takes place – it only controls when the group is active. (In this case only when the PDF-app is frontmost.)

A click from Keyboard Maestro is going to click anywhere the system can click, since KM is in fact just driving the system.

Here's a quick example that does what you want.

Execute Macro Based Upon Screen Position of Mouse Cursor.kmmacros (2.6 KB)



Works like a charm!
Thanks a lot!

Just a followup question, how do I put exact coordinates into this?
Tried searching through wiki function screen() but my programming sucks. :stuck_out_tongue:

I want to offset the menubar + application titlebar as well. I tried this: "MouseY() > Screen (Main,Top,100)" but doesn't work
(The Top offset is ~100px for me in this case)

Also would love to exclude dock dimensions if I know how to put in exact coordinates to this.

Thanks in anticipation

MOUSEY() > 100

1 Like

Oops. Feel pretty stupid right now. Thanks a lot. :slight_smile:

We all have those occasional “DOH!” moments... :wink: