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.
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.
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.
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?