How to create a toggle macro for continuous mouse clicks at cursor position?

I’m looking to create a smart macro that does the following:

  • When I press a specific key (e.g., F6), it should start auto-clicking at the current mouse position
  • The clicks should be left mouse button clicks
  • The clicks should continue automatically until I press the same key again
  • The mouse position should not be locked - clicks should happen wherever the cursor is
  • When I press the key again, all clicking should stop

Is this possible with UHK smart macro? Thanks

1 Like

I created below macro. Is it correct? I set clicking to 0 in $OnInit.

I think you are on the right track. I have this example for you that does a similar thing. It counts down from 30 to 0 in 1-second intervals and shows the counter on the UHK 60 LED display. If you run the macro again while it is already active, it will stop.

The main code is in this macro, and it’s bound to fn+c.

countdown:

if ( $count > 0 ) final setVar count 0
setVar count 30
loop:
setLedTxt 1000 "$count"
repeatFor count loop

To make this macro work without errors, some initialisation is needed in $onInit:

setVar count 0

In addition to being the actual counter, count is also used as a semaphore to detect a second invocation of the macro while it is already running, and stops it by setting the count to 0 - this will cause the already running loop to exit (the repeatFor will not repeat anymore).

1 Like

The macro is called $onInit. Lowercase o.

1 Like

Oh, it’s a typo. I’m using $onInit. Thanks for pointing it out.

I managed to make it work. It seems that a single statement like while can’t cross two command blocks. I use below code to eliminate the use of while and still do the trick.

5 Likes

That sounds like a great idea for automating clicks! With UHK smart macros, it should be possible to set up a toggle function for continuous mouse clicking at the current cursor position. Just make sure the delay between clicks matches your preferred mouse clicking speed to avoid issues with responsiveness. Have you tested different click intervals to see what works best for you?