Hold Key Recognition (Works With MIDI as Well)

This macro will recognize if you're holding a key for a given time, and execute a macro if you do.
I use it to enable and disable macro groups with a MIDI device: If I hold a button down for 1.5 seconds, it'll disable a macro group, and enable another one.
Ofcourse you can make it do whatever you like.

It uses 2 different macro's, but both using the same key/button.
Here it is:

The moment you press it, it will set a variable to 'on'. Then it waits for 1.5 seconds (or whatever you make it), and checks if the variable is still set to 'on'. If it is, it'll execute the actions you'd like to happen when holding the key.
I placed a sound there, so you know when you can stop holding the key.

Now, if you were to set the variable to 'off' within that 1.5 seconds, it wouldn't play the sound (or whatever you put in).

That's where my next macro comes in:

If the same key/MIDI is released (where you set your hotkey), this macro will set the variable to off. If the variable is set to off after the 1.5 seconds have passed, it will have executed the actions anyway, so it doesn't matter, it'll just reset the macro.

But, if you released the key before the 1.5 seconds have passed, the first macro would recognize that the button is not being held anymore(because the variable is still set to 'on'), and not execute the actions within the group.

That's it :slight_smile:
.
.
Using this configuration, you could even set an action before the pause, which will always be executed, even if you held the key for more than 1.5 seconds.

I have it set up where my MIDI button will always reset another variable, and if I hold it for 1.5 seconds also switch to another set of functions for my MIDI buttons and knobs.

Test it:
Hold key recognition.kmmacros (4.8 KB)