How to set up a trigger that triggers one or two actions

I’d like to use KM to replicate something I’ve already done with BTT. I know how to set up the macro. The problem is the trigger. It’s a short/long press trigger.

Normally, this works with KM as follows: a short press is triggered when the key is released. A long press is also triggered when the key is released, but it must be held down longer.

I want a trigger that always fires when the key is pressed, in both cases short and long pressed.

This means that the long-press action always triggers the short-press action as well. But the short press action never trigger the long-press action. Is that possible? Thanks for your help!

I need this to format text starting from the cursor’s current position without using any modifiers. It looks like this.

Bildschirmaufnahme 2026-08-31 um 15.17.40.zip (259.7 KB)

Macro A, trigger on key press

  • Set variable "Doing Macro A" to 1
  • Perform Actions For Short Press
  • While variable "Doing Macro A" is 1 (time out long press time, no abort on timeout, no notification on timeout)
    • Do nothing
  • If variable "Doing Macro A" is 1
    • Perform Actions For Long Press

Macro B, trigger on key release

  • Set variable "Doing Macro A" to 0

@peternlewis has given one way using two Macros. If you wanted to do with a single Macro you could also to something like this:

Here's another. The main benefit is that actions trigger as soon as a long press is detected, rather than having to wait until after the trigger is released.

Uses the subroutine found under Hotkeys & USB Device Keys at the top of this post:

Thanks @Zabobon an @peternlewis
If I understand correctly, in your solutions, at least one macro is triggered when the key is released. Unfortunately, that doesn't work for my purposes.

And thank you very much @noisneil
With your macro, I can press a key, then Macro 1 is triggered; if I keep holding the key down, Macro 2 is triggered as well. Is that right?
Would you be so kind as to post your macro?

If I may ask one more thing, I seem to recall that KM has a condition “if text is selected.” Am I right? Unfortunately, I can't find it anymore.

There is no such trigger. Detecting selected text is usually done by checking for the Copy menu item being active.

-rob.

If you tap, action A runs.
If you keep holding, macros A and B run sequentially.

It's included in the macro post I linked to as an example caller. Just insert your actions and pick a trigger. Note that you must have a press and release trigger.

Hmm, what exactly does that mean? When I say “tap” I think of a quick down/up movement. But is the macro triggered by “down” or “up”?

Down and up, quickly, is a tap.

I'll try it another way :slight_smile: If it works like this “tap” then the macro is triggered when “A” is released.

Your request could be a little clearer. Is this what you're after?

Trigger down runs Action A.

If released quickly, no further action.

If held, run Action B.

But in your original question you said:

So, that means the long press action triggers both macros and the short press triggers only one of the macros. In each case at least one Macro is triggered which is what the solutions above do.

I'm trying to work out what you want to happen :smiley:

Is it:

One Trigger for running Macro A
One Trigger for running Macro B
One Trigger for running Macro A and Macro B

So, three different possibilities?

...after being down a short time. That bit's important.

"Is pressed" fires on key down (not on release, as you state in your OP), while "is long pressed" is on key release.

Like @Zabobon, I'm a bit confused as to the combinations you want. But I'd note that you can't have "short press only" macro that fires on key-down while also using the same trigger as a long-press...

Gentlemen :slight_smile: I apologize if I didn't express myself clearly. I thought I had covered everything essential with this sentence.

Apparently not. It's probably due to my poor English.

In any case, this is a completely accurate summary.

I think I know what you're after. Maybe.

Hotkey-USB - Press Detection (Action on Key-Down).kmmacros (78 KB)

Macro screenshot

Hotkey-USB (Caller Template) (Action on Key-Down).kmmacros (40 KB)

Macro screenshot

I've added placeholder actions that simply display the press-type large on-screen for testing.

The long-press duration is set by adjusting the timeout of this action in the main macro, via its gear menu. I've set it to 0.5sec to make the effect more obvious, but I usually have it set shorter:

Thanks, @noisneil yeah, that's exactly what I wanted. Man, for a normal person, that's incredibly (pointlessly?) complicated (impossible?) to set up.

No offense to anyone or KM, just sharing how it could be done differently.

A key is pressed for a maximum of 0.5 seconds (maximum hold time) but released before. That triggers Macro 1, but not Macro 2.

The same key is held down for longer than 0.6 seconds (minimum hold time), that triggers Macro 1 and Macro 2.

Thank you all :slightly_smiling_face:

Actually, it can be significantly simplified. Here's a single macro that does away with multi-tap detection and instead...

  • Does action A on initial press
  • Pauses for the trigger to be released, with a timeout of 0.5s
  • Does action B if the timeout lapsed (i.e. the trigger is still being held)

Hotkey-USB - Press for A + Hold for B.kmmacros (37 KB)

Macro screenshot

Then, unless I'm still mis-understanding, what's wrong with a simple:

Short and Long Press.kmmacros (5.3 KB)

Seems to behave as requested, unless I'm missing something.

Hi @Nige_S , I'm not at my computer right now, so I can't test. But from what I see on the screen..

There's nothing wrong with your solution. That's one way to do it. But you're actually missing one detail, and I'm glad it was noisneil who formulated it that way. :slightly_smiling_face:

I don't think your macro does that. As long as the key is held, nothing happens. Action B isn't executed until the key is released, as far as I can tell without testing.

It’s just a strong preference of mine that I see action B happen while I’m holding down the key.

Ah, gotcha. So you don't want a "long press" to trigger the macro, you want a "press and hold" -- which isn't a KM trigger so, yes, you'll have to use @noisneil's excellent solution or roll your own functionality.

I'd use @noisneil's, since he's been kind enough to do all the hard work :wink: