Determine if Hot Key was Long Pressed/Tapped Once/Double Tapped

Is it possible with something similar to %TriggerValue% to determine if a macro was triggered by a long press, a tap, a double tap, and so on?

For example, now that in KM11 we can have "long press" and "tapped only once" as triggers, you might want to do one action when the macro is long pressed, and another when tapped once. If these actions are similar it might be easier to do this within once macro, rather than two different ones.

I see your point. I tried it out. But I think you are overlooking something. If two separate macros are triggered by two separate key-presses, they can still run the same code by each of them calling a third macro. Macros are like subroutines, and recent versions of KM allow you to call macros like subroutines, where you can pass many values. In your case, you could pass the value representing the key that was pressed, if you need to pass that data to a subroutine.

It sounds like you already realize that if the key that's pressed is different, the %TriggerValue% has different contents (I'll add an image below). Now you want to know if there's something like %TriggerValue% that will carry information about the trigger, not just the key. I don't think there is, which is why you will have to create different macros, and if they have "code in common" you could create a third macro.

In the above example, the macro could tell the difference between the first and second trigger because the actual key that triggers it is different. If both keys were identical, I'm not sure that there is a way, other than using the technique I described above.

Thanks for the response!

Here's an example of what I want to do, using USB Device Key, and a modifier to do my alternative action.

If I press 'M' I want to export with a certain preset, but if I hold M, I want to set this variable (which is recalled in the other macro, to do some handy things)

Because I have lots of other macros in this palette that choose different presets, depending on the key I hit, I'm trying to avoid doubling them.

I appreciate it might not be possible, which is why this is halfway between a feature request and question.

I see a problem in that requirement. The moment the key is depressed, it will trigger an action. And I think you are saying that you want a HOLD on the same key to do something BEFORE the action occurs. But that would be about a half second too late, because hotkeys trigger actions when they are pressed, not when they are let go. Do you see what I mean?

My last post said you don't have to double any code if you put the common code into a third macro.

But we now have the 'tapped only once' trigger, which doesn't fire the moment the key is depressed

Fair point. Let me reconsider. But the answer might be the same.

I think I've found a way. Hmm.... My idea was to check the value of the IDLE() function, which at first I thought would be based on the time that the key was pressed, but now seems to be based on the time that the key was released. So that doesn't seem to help. It was a good idea. I'm still pondering. Okay, I found a way. You probably won't like it, because it's not a built-in feature of KM. It takes some work. Here's what the end result looks like. I've made it use the F1 key instead of the M key, simply because I use the M key to type. I also had to create a variable called F1up and F1 down. Each variable is set to the value SECONDS() whenever the F1 key is pressed or released (those are second macros.)

I actually have ideas that might be even better, but they aren't working yet. But if you want absolute perfection, then you may have to use my idea of creating two macros, and calling a common subroutine. That's even less work then my solution below. To be honest, I don't think your idea is bad for a way to distniguish in KM. Perhaps there should be a new token called %TriggerKind% which could be "Tapped Once" or suchlike things.

I'm not sure if I understand this correctly, sorry if I don't. But if the problem is that a long press action is triggered when the key is released, then @noisneil's multipress macro could be the solution. It reverses this.

Do whatever you want. But passing common code to a third action is a trivial solution that would work fine. Like this:

And you do the same thing for "Long Pressed". I can't see why this solution isn't perfect.

If you want to use KM11's native multi-press trigger options, then what you're looking for is %Trigger%.

Native Multipress Template.kmmacros (29 KB)

Macro screenshot

The red actions will display the detected taps or long press. Replace them with whatever actions you'd like to run.

4 Likes

I did not know about that token at all. That's the solution.

1 Like

Hi @noisneil,

I downloaded your macro and gave it a try. When I tap the hotkey 4 times, it triggers all the displays from tapping once, twice, 3 times, and 4 times. Shouldn't only the Display Text "4" Large be displayed?

Demo Video

test1

You've changed the trigger types. Look for the "is tapped ONLY..." triggers.

You didn't need to create new triggers from scratch; just recapture the hotkeys.

I'm still on KM 10.2, so maybe that's why I do not see "is tapped only.."

1 Like

Yes, this is a new addition to KM11. If you're not planning to upgrade (and even if you are) check this out as an alternative.

1 Like

I laughed when I read your post, because your large numbers appearing on the middle of my screen made me think my own Engine was displaying them.