This macro will jump the mouse between two displays, with a couple of very important limitations:
It only works for two identical-resolution displays.
The displays must be arranged side-by-side in the same orientation.
The macro could be extended—with a lot more mouse and screen calculations—to handle more displays and more layouts and differing resolutions, but as I don't have any of that, I didn't spend any time trying to figure it out. If you want to modify and redistribute, please go ahead!
EDIT: Don't use this one, see below for much better solutions!
Macros are always disabled when imported into the Keyboard Maestro Editor.
The user must ensure the macro is enabled.
The user must also ensure the macro's parent macro-group is enabled.
System information
macOS 14.7
Keyboard Maestro v11.0.3
If you do have a monitor layout that meets the requirements, though, this macro can be a big time (and wrist!) saver for those times when you have to mouse between displays. I have it mapped to one of the thumb buttons on my mouse, so I can easily flip between displays while moving the mouse.
The mouse moves from the current display's X,Y location to the same X,Y location on the other display. Invoke the macro again, and it moves back to the X,Y location on the first display.
It should work regardless of which display has the menu bar, and the status of the "displays have separate Spaces" setting. At least, it did in my testing :). The macro shouldn't require any editing to get going, unless you want to change the shortcut keys.
If you change the modifier keys for the shortcut, make sure you update the green box to match: This makes sure that modifier keys aren't sent with mouse moves, which can be troublesome if you use an app like our own Moom, which can be configured to do things on "mouse move + modifiers down."
Here's a generic version which should, I think (limited test setup here), jump the pointer to the same relative position on the next screen (by index) -- regardless of resolutions or arrangement.
Feedback from people with multiple monitor/resolution setups much appreciated!
I never hate a simpler solution! The first version works perfectly with my setup—thanks!
As I was working on this last night, I was thinking there must be a simpler solution, but didn't even think about combining screen index and mouse. Lovely!
You should be able to get it down to a single "Move Mouse" action by using ternaries in the Calculation fields to do the "If..." part.
There would, of course, be a reduction in readability. So why do it?
I've a working theory that
Even complex calculations are near-instantaneous
There's a minimum on how long any action, however simple, will take. More properly, any single executing instance is only allowed a certain % of processor time -- even if an action completes in a microsecond, the instance's next action won't be evaluated until the next slice of processor time comes around
That would mean that combining two actions into a single calculation would almost halve the time that part of the macro takes. And the more actions you combine, the greater the saving!
Given it already moves quicker than my eye can move from one display to the other, it's plenty fast ... and I'd probably spend 10 hours trying to figure out the proper structure of the command to make it work (logical coding is not a strong suit of mine).
Thanks for the simple solution; I was using one of our own apps to do this, but that's all I was using it for, which seemed like overkill. Having it integrated in KM makes much more sense.