Detect where the mouse is (north, south, west, east) and do an action based in the position

Hello,

I would like to know if its possible to detect where the mouse is in the screen (north, south, east, west) and do a action based in the position.

Example:

  • I press F1, my mouse is for east, so my macro detect that and than press ctrl+arrow right+F5
  • I press F1, my mouse is for south, so my macro detect that and than press ctrl+arrow south+F5
  • I press F1, my mouse is for west, so my macro detect that and than press ctrl+arrow left+F5
  • I press F1, my mouse is for north, so my macro detect that and than press ctrl+arrow up+F5

Is it possible?

Hi @Seabra - you can use the two functions MOUSEX() and MOUSEY() to get the position of the mouse pointer on the screen. From there you can then decide whether those coordinates mean “North”, “South” etc. And perform whatever actions you wish.

See, for example, the KM wiki definition for MOUSEX() at function:MOUSEX [Keyboard Maestro Wiki].

1 Like

some start:

image

You can then determine what is North

1 Like

Hello Tiffle! Thanks again!
Ive tried to use this functions, I got the right position etc but I don't know how can I make the macro understand that it is in north south east west. Ill keep trying thanks so much!

1 Like

Thanks so much hello, it was a really good start! I still couldn't make the macro recognise where is the position, north, south, east, west but ill keep trying.

OK - getting the right position is a good first step.

Tell us, what is “North”?

If you take a screenshot of your screen and then markup which areas are north, south etc. it would be easier to help

1 Like

Quadrants, presumably ?

Cursor quadrant ?.kmmacros (4.9 KB)

2 Likes

Hi @Seabra - just for the benefit of those who look at this in the future - did you find a solution to your problem?

Thanks to all for your valuable help. I would like to have a solution without the help of user interactions (with the mouse), but probably this is not possible. There is the Window API getScreenDatails that could possibly do this, but it is not implemented in Safari yet and there is no info if it will ever be implemented.

With User-Interactions I had also helped myself so far to realize a solution, because I get the ScreenBounds of all connected screens (ordered by screen index) with the help of the KeyboardMaestro SCREEN() function. Then, of course, I can use onmouseenter (bound to the element, for example) to get the position event.screenX and event.screenY and only need to compare this with the ScreenBounds to get the index of the screen on which the Custom HTML Prompt window is displayed.

This also works regardless of the screen arrangement.

Why I don't like the need for user interaction with the mouse so much is because I like to know early on when the user is going to move the Custom HTML Prompt to another screen, i.e. the mouse query needs to happen then too. Of course, this can also be achieved with the mousemove-event. But so far I didn't want to load the CPU with that.

Thanks again for your interest and help!