Lock mouse while macro

Hello! im trying to lock my mouse while he moving and do macros, so i cant move it mistakably. anyone knows how?

Hi @avinaf - welcome to the KM forum.

When this question was asked previously, the answer was “no”.

See:

As @tiffle says, I don't think that can be done.

In my case I make use of Keyboard Maestro's Progress Bar to warn me not to move the mouse while certain Macros are running or starting up. Here is an example. The example has a pause of 10 seconds that is a placeholder for your actual Macro. It also puts the warning right in the centre of the screen so I can't miss it!

To explain the mechanics of the Progress Bar - putting in a value of -1 causes the Progress Bar to pulse and a Value of 100 closes the Progress Bar. Other values would put the Progress Bar at different points. 50 would put it half way, 99 would put it pretty much full.

So, instead of having the Progress Bar pulsing, you could dot it though your Macro at known points and set it to actually show Progress.

EXAMPLE Use Progress Bar as Warning not to Move Mouse.kmmacros (3.4 KB)
EXAMPLE Use Progress Bar as Warning not to Move Mouse

Here is how this simple Pulsing warning looks:

Screen Recording 2022-03-07 at 13.40.11-Animated GIFF 640 12fps

And here is one with the bar moving across to indicate progress (this is in an actual Macro I use for Backups). As the numbers and the title in the Progress Bar can be Variables it is open to all sorts of tweaks.

Screen Recording 2022-03-07 at 14.27.29-Animated GIFF 640 12fps

2 Likes

Is the point of this request

(a) to stop the user from clicking, or
(b) to allow the user to click while not being able to move the mouse, or
(c) to stop both moving and clicking?

Even if it's not possible, you might be satisfied with a macro that, whenever the user moves the mouse, fills the screen with a big warning to not move the mouse, like this warning:

I haven't actually give up on the idea of stopping the mouse. I'm still researching that, but I suspect you might like a warning macro just as much. If you are happy with a warning, I can write that up for you. In fact, it looks so fun I'm going to write it up whether you want it or not, and I'll post it in the Macros forum on this website.

Maybe, or maybe not. If the mouse is Bluetooth mouse, then there's probably a way. That's because there are ways in macOS to reconfigure and relaunch the bluetooth daemon, something like this: (you may need to sudo to achieve this, and if you don't know how to sudo, you shouldn't be trying this until it's debugged. This code doesn't seem to work on Monterey. It may have worked on other versions of macOS.)

defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 0
launchctl unload /System/Library/LaunchDaemons/com.apple.Bluetooth.plist
launchctl load /System/Library/LaunchDaemons/com.apple.Bluetooth.plist

There are also utilities that let you disable specific bluetooth devices, (you have to insert the bluetooth address of your mouse to make this work) like this:

$ brew install bluetoothconnector
$ BluetoothConnector --connect 00-11-22-33-44-55 --notify
$ BluetoothConnector --disconnect 00-11-22-33-44-55

A thorough discussion of either of the above options may require a new thread. However I'm working on a third and maybe a fourth option that is so huge in scope it definitely requires its own thread.

@Sleepy Did you succeed?

A very simplistic and crude method for locking the cursor movement at certain stages of your macro can be achieved by setting up a Move Mouse action within an Until. This approach have kind of limited use cases, but I actually use it for some of my macros.

Lock cursor for N seconds DEMONSTRATION.kmmacros (19 KB)
(v11.0.2)

Macro Image

My main use case is using it as an alternative to a Pause or Pause Until action between Move and Click Mouse actions (in cases where a pause would anyways be needed). This way locking the cursor to the last automated mouse movement, for instance waiting until the next button in the automation chain appears (the conditions of the until will need to be set accordingly for this to work, of course).

It can also be used at the beginning of a macro, that is about to automate mouse movements, to indicate that you are now not in control of your mouse. How effective this method is at disincentivising the user from further mouse movement depends on the users temperament though — some will only start attempting to move the cursor in a more erratic and aggressive manner, while for others this can be a very subtle and effective way to make them give up mouse movement for a while, while the macro is doing its thing. This method is usually best paired with a form of text based alert though, like demonstrated by @Zabobon and @Sleepy above.


Lastly I here want to add a WARNING that placing a Move Mouse action in a loop like this can quickly lead you to loose control over your mouse. So I strongly advice having a Cancel All Macros action set up in a hot key triggered macro, in global macro group (and remembering that hot key) before experimenting with this approach.

2 Likes

Thank you for your macro and a big thank you for reminding me that it's not enough to place a Cancel all macro in the menu bar, but that I also have to assign a keyboard shortcut :).

2 Likes