Mouse Get Coordinate if Pressed with Modifier / Mouse move without the Modifier

Hello, I'm new to KM.so Pardon my noobness. I've been using Autohotkey for windows. I wanted to have a similar function in KM and M1MacPro.

Basically what I want is a mouse get and mouse move action
Is it possible to add an apple script instead of using the Mouse move actions? That When I use the CONTROL Modifier and with the trigger, it gets the mouse coordinate and saves the x,y, in the action. And when pressed without the Control modifier mouse move at the saved x,y coordinate.
ie...press Control+F1 = saves the current mouse coordinate where the mouse pointer is
press F1 = moves the mouse to the x,y coordinate.

Yes, there is a Mouse Action but I don't want to setup manually. All I want is to use modifier +the trigger to get the Mouse x,y.

I will be grateful to those who can help me. Thank you.

You can do this with two Macros.

The first one has the trigger ⌃F1 and saves the coordinates of the current mouse to a Variable (I named the Variable "SAVED__Mouse" but you can name the Variable what you want).

The second Macro has the trigger F1 and uses the coordinates saved in that same Variable to move the mouse to that coordinate.

Macro 1 (saves):
EXAMPLE Save Mouse.kmmacros (2.0 KB)

Macro 2 (restores):
EXAMPLE Restore Mouse.kmmacros (2.0 KB)

To break down what is going on. In the first Macro, %CurrentMouse% is a Keyboard Maestro Token that will always be the coordinates of where the mouse currently is. Notice the greyed out numbers at the bottom of the first action - they show what the Variable SAVED__Mouse is currently storing and what it will store if you ran the Macro now. If you have the Macro open in the Editor and move the mouse around you will see the second set of numbers changing depending on where the mouse is.

image
So, 1753,932 is the current mouse x,y location.

And in the second Macro those coordinates (which were grabbed in a kind of snapshot when the first Macro was run and stored in the Variable) can be used to restore the mouse location.

Can this be applied by say instead of F1 keystroke. I use MIDI notes as Trigger?

Or instead of putting a trigger I will us KM link in Streamdeck?

Yes, you could use any triggers. I only used ⌃ F1 and F1 because that was what you were asking for.

At the top of the Macros, change the triggers to whatever you would like.

Click to Show Image

I will experiment and give feedback. Thank you so much.

1 Like

Is there a way to have a trigger that uses Control and Midi note? whereas Control will act as the modifier and Midi Note acts like those hotkeys?

What if I wanted to do many Macro command and would want the X,Y coordinate on every macro be saved into one jason file? how to do that?

ANd Is it possible to Put both Assign and restore mouse in One Macro? say Pressing a MIDI Key to Save coordinate and pressing another MIDI key to restore but put in a singe macro?
Color.kmmacros (17.8 KB)

or something to this effect.

If MIDI note =1 and channel=1 is pressed
Save_mouse coordinate, x, y

If MIDI note =1 and channel=2 is pressed
Move_mouse coordinate, x, y

When you use something to trigger a Macro in Keyboard Maestro that "trigger value" is known to Keyboard Maestro in a Token %TriggerValue%

So, you can set up a Macro to fire with two triggers (eg Channel 1, Note 1 and Channel 2, Note 1) and do different things depending on what was actually pressed (the value stored in %TriggerValue%).

I don't have a Midi device hooked up right now but from the Keyboard Maestro manual it says that the Values stored when Midi Keys are used as Triggers are a comma separated list:

So you can use this information to set up a Macro that does two different things depending on what was actually pressed. Something like this, (where the Green Actions would be replaced by saving and restoring the mouse position).

Example Two Midi Triggers (do different things).kmmacros (17.6 KB)

Going forward, you can also directly see what values are held in %TriggerValue% by making a simple test Macro that displays them, something like the below (this would display the value ⌘A when triggered by pressing ⌘A)

Thank you so much.
I got it working.

1 Like