Click and hold mouse button Macro?

Hi, I'm trying to create a click and hold mouse button Macro; my aim is to drag an object without having to keep the mouse button pressed, Is there a way to do this with KM? What I would like to do is press an hotkey and this will keep the mouse button pressed until I press again the same hotkey; I did a search on the forum but it seems nobody have found a reliable way to do this. Maybe version 10 has some new features regarding this aspect?

This page in the KM Wiki has some good info that will help you.

[action:Move or Click Mouse [Keyboard Maestro Wiki]]

Thanks for your reply but the thing I'm trying to do doesn't seems to be covered. I already have done macros with simple clicks at current position or clicks at specific screen coordinates but I can't find a way to click and keep the mouse button pressed with a keyboard shortcut

It's in the "Mouse Drag Options" -- "and hold".
clickAndHold

It says on the Wiki that buttons "stay pressed only as long as the macro continues to run", so you may have to create a macro that triggers on a hotkey, does the click-and-hold, then pauses until you press another key combo (or similar action).

Thanks for your reply, I already tried drag and hold with no success but now, thanks to what you wrote, I understood that the problem seems to be in the trigger and not the macro itself. So my question now is, how do I create a macro that continues to run until I send another trigger?

You cannot mix simulated and hardware actions. You can simulate clicking and holding, and you can simulate dragging, but you cannot simulate clicking and holding and then physically drag.

Simulated events and Hardware events have largely independent state.

Before you go down this rabbit hole -- have you tried what's already available on your Mac?

System Preferences->Accessibility->Pointer Control->Enable alternative pointer actions, and assign a keystroke to "Drag and Drop".

First press of the keystroke should be a "click and hold", next press a "release", allowing you to position the pointer on an object then keystroke, then move the object then keystroke to drop.

Thanks a lot for your reply Peter, I actually did this a while ago with MIDI Translator Pro, a software that, among other things, is able to translate MIDI messages in mouse or keyboard action. I programmed a button on my MIDI controller as Mouse Click On and Another as Mouse Click Off and I can drag just moving the mouse. I actually did this just to try the software because what I wanted to really try is if I could use a MIDI controller that's physically connected to my PC to also control my Mac, thanks to another piece of software from the same developer that's called Bome Network. I ended up finding this dragging without keeping the mouse button down quite useful, especially for moving virtual knobs or faders so I started thinking that I could realize something similar with KM given that when the PC is off I don't have a MIDI controller connected to my Mac.

Thanks a lot, that's a great suggestion! I'm still on Mojave on my two Macs this and option is not available, it's been implemented with Catalina AFAIK, but I'll upgrade to Monterey in a few weeks, so I'll definitely try this out

Be aware that many softwares/devices that spoof mouse or keyboard hardware events do so via virtual keyboard kexts and, since Apple have made those all but unavailable to developers, things like this mouse-click that are working for you on Mojave may break badly on Monterey (see eg the ControllerMate discussion here).

Thanks for the advice, I'm forced to upgrade anyway because I'm getting a new Mac, and the integrated solution you suggested before could be the better answer, we'll see, I'm only trying to ease the pain that I get from prolonged mouse usage. In this regard KM helped a lot during the years, given the large amount of keyboard shortcut (and metagrid buttons more recently) that I can use

Then perhaps this'll help you some more -- just a quickly knocked-up proof of concept but if you put the pointer over something -- I used a file in a Finder window set to "Icon" mode -- and run the macro you can then use your keyboard's arrow keys to move the file up or down 10 "pixels" at a time, then hit ⌘ESC to drop it.

Not quite the direct interaction you'd get with the mouse, but it could be the start towards something useful...

Click and Move Mouse with Button Down.kmmacros (8.6 KB)

Summary

Actually your Macro is way more useful than you think, because in the Audio software where I wanted to use this kind of macro (Cubase, Reaktor, Absynth), with your macro I can also move the mouse and (I don't know why) the parameter moves, exactly as I was hoping! Also, I have the bonus of moving it with the cursor keys, great!
The only thing that I don't understand is that the movement is way more than 10 pixel; I tried to reduce the value to 1, and it's better, but it's still way more than 10 pixels and decimals values don't seems to work at all

I think that the loop runs so quickly that it can respond multiple times to a keypress, machine-gun style. Try putting a short pause, like 0.1 seconds, after each of the move mouse actions. You could also try "Pause until (up or down, respectively) arrow key is up" if you only use single presses rather than hold down to repeat.

(Ultimately it's because we are asking "is the key down" rather than "was the key pressed".)

Thanks for the suggestion, probably that was the case but it wasn't so bad for my intended usage, the reason I asked was more because I want to understand what I'm doing than fixing the macro; if the move mouse action values are in pixel that didn't seems what I was getting. Anyway I ended up putting a 0.01 pause (one tenth of what you suggested) and it seems like a good compromise. Also consider that, in the software I mentioned, if you press the shift key while dragging you get a finer resolution, and this works also with your Macro.
Thanks a lot again, you saved my day! (and possibly my wrist)