Held modifiers, repeated keystrokes and a latching switch

I'm trying to set up a KM Macro using a latching switch in Metagrid as a trigger. The first press (down state key command) of the button will start the macro running, the second press (up state key command) will stop the macro running. With the cursor already in place triggering the macro would select word after word in a line / paragraph / page of text (Pages Key command: shift and alt (both held) / right arrow repeated) in a Pages document until the up state was engaged.

I'm using this example as something of an academic exercise - if I can do this, it opens up a lot of other possibilities. Right now I'm struggling with held modifiers.

Is it possible?

I have a repeat macro template you can find here.

Using that template, this repeatedly highlights the next word until you release the trigger:

Hotkey - USB 3 - Repeat - Highlight Next Word.kmmacros (42 KB)

Macro screenshot

The repeat speed is determined by the green action. A smaller value equates to faster repeats.

2 Likes

Thanks so much for this - there's quite a bit for me to take in here but I think I can follow most of it. I'll let you know how I get on.

Much appreciated...

1 Like

@noisneil's solution is perfect (as always), but not so easy to understand (for beginners like me). Therefore just think about what you want to do. You want to press and hold ⌥⇧+arrow but want to use another hotkey for it. In the simplest version, you can do this.

1 Like

Simpler is probably better, so if you don't need control over repeat speed, @Frankb's solution is perfect.

1 Like

Do you see a way to add speed control to the simple solution?

Yes, just add a pause after the simulate keystroke. Adjust the length for your needs.

Actions Screenshot (click to expand/collapse)

Actually, no. That will still repeatedly trigger the simulated keystroke at full speed.

What you could do is use a conditional variable like this:

Highlight Next Word (Repeat).kmmacros (22 KB)

Macro screenshot

The advantage of the template I mentioned previously is that an additional action can be triggered on key release and mouse position can be recalled. For something as simple as highlighting words, that's probably not necessary.

1 Like

This looks good!!! Pressing/releasing is not necessary here, because the trigger "is down" has already "integrated" the releasing, so to speak :joy:

Yeah. It's more for things like:

Hold: repeat action A
Release: action B