Short Press Shortcut Do One Action, Long Press Do Something Else

Keyboard Maestro “Trigger Option Using Long Press of HotKey [Example] - Increase Number by One” Macro

Trigger Option Using Long Press of HotKey [Example] - Increase Number.kmmacros (14.5 KB)

You're right it isn't much longer in the benefit of yours is I could follow it I counted 11 needed actions for yours and 7 for Dan's. 10 if you don't use the last action to clear it out to be safe and then you would need the action to set the variable if you don't have the keys pressed down, so I guess you could remove one or the other leaving you 10 (I didn't count the Display Text action I left in there). Your macro you had to set a variable and then use that variable's result to then choose to do the next actions where Dan's doesn't seem to need an extra variable to then do the variables he has in his macro. Some sort of magic voodoo is being done with ^\d\d?$

Also I noticed that I can keep the modifier held down with Dan's when one is set and release the action key (i.e. Command+F4 I can still hold down command and release F4) and it will then do the short press. I realized that in order to get that same behavior I couldn't just not select any modifiers I actually had to remove the modifier option. Otherwise I have to release the modifier and the action key to get it to work which is not as natural to me. If I take off the option for the modifier then it never does the short press action, a bit confusing but good to know.

Thank you for your reply and help.


Short Press Shortcut Do One Action, Long Press Do Something Else - Questions & Suggestions - Keyboard Maestro Discourse

2021-11-08 02:05:44


If you want simple and compressed, here it is.

BTW, your macro failed if the first execution was a normal press because the "MyCounter" variable did not exist.

A long press of the trigger, ⌘1, will reset the counter to zero.

MACRO:   Increment Number [JMichaelTX]

--- VER: 1.0    2016-10-14 ---

DOWNLOAD:

Increment Number [JMichaelTX].kmmacros (4.2 KB)


image

@skillet, @DanThomas answered your question.
For future reference, here's a great site to test and understand RegEx:

For example, it will show you this:

@skillet:

Here's a minor update you may want to make to cover the case where MyCounter exists, but is not numeric:

As soon as Apple adds a prescience API, so I can tell in advance whether you are going to press it a second or third time or not, I will be happy to implement it this way.

You can do what you want in a variety of ways, but all involve adding a delay to the first and second macro to see if another trigger will fire.

For example:

First
Trigger: tapped once
Action:
Set Do First to 1
Pause
If variable Do First is 1 then
Macro A

Second
Trigger: tapped twice
Action:
Set Do First to 0
Set Do Second to 1
Pause
If variable Do Second is 1 then
Macro B

Second
Trigger: tapped thrice
Action:
Set Do Second to 0
Set Do Third to 1
Macro C

Oooh, I want that too! But then again, if they had that technology, they'd already know I want it...

:wink:

1 Like

LOL LOL, yeah the word thing is funny Dan, - =)
Peter, thank you for your reply and your other replies to my ‘beginner’ posts.
Since ‘coming over’ from quickeys, I really want to tell you that I am SO enjoying being a part of this community AND having such strong, flexible, supported software to work with.
~ Can’t thank you enough or say enough positive things about KM. -
nice

Here's a template for creating macros that allow multi-press hotkeys:

WOOF! just awesome Dan, - flexible, quick, .3 seems perfect timing for the delay, but can adjust, nice, THANK YOU-

1 Like

Oh wow thank you, I can wrap my head around that, very efficient and compact.

Very nice thanks for sharing, https://www.regex101.com is completely new to me and seems a bit daunting, I'll have to read up on it http://www.regular-expressions.info

Good point I didn't think of that since I had already run it before several times. [quote="JMichaelTX, post:14, topic:4855"]

Here's a minor update you may want to make to cover the case where MyCounter exists, but is not numeric:
[/quote]

Hum, looks like I'll be learning about Regular Expressions in the future.

Here is one slight modification if anyone might come across this and find it useful to be able to type in your own number with a long press that I added and have been using from @DanThomas macro, I added to what @JMichaelTX just posted.
Increment Number [JMichaelTX].kmmacros (4.2 KB)

1 Like

www.​regular-expressions​.info is very good, but if a regex doesn’t work as expected in KM don’t forget to look up at the ICU page, since this is the regex flavor used in KM.

I know I thought they would have released the Time Machine API by now, you know they have one. How else did they get so crazy rich in such a short time?!

Thank you very much Tom, good to know. So if I understand right anything on this page should work in Keyboard Maestro ICU User Guide | ICU Documentation

Hi Peter,

Since KM recognized pauses between taps is so critical to using this feature, is there any way you could program the actions into a downloadable macro? Using the fastest, most reliable actions? I understand the "pause" timing has to be set individually based on your circumstances. It's just I see all kinds of ways of doing this, some very complex like this:

[Like this, although maybe this was earlier versions?]
(MACRO: HotKey Multi-Press Template (Double-Press, Triple-Press, Etc.))

There are examples of using this variable counting keystrokes, text variable, all kinds of stuff.

Seems like this could be programmed into KM's tap trigger itself. Next to tap (once, twice, thrice) another data field, "wait x number seconds before execution" to allow another tap. You could always leave it blank or enter 0 if didn't want a delay.

Here is what you wrote:

First
Trigger: tapped once
Action:
Set Do First to 1
Pause
If variable Do First is 1 then
Macro A

Second
Trigger: tapped twice
Action:
Set Do First to 0
Set Do Second to 1
Pause
If variable Do Second is 1 then
Macro B

Second
Trigger: tapped thrice
Action:
Set Do Second to 0
Set Do Third to 1
Macro C

I'd be using an xKeys. Which "actions" are you using to program this? I'm confused about the second "second". Do you mean "Third"? Is there a pause in that one?

What's the simplest way to

  1. Tap once on an xKeys, have KM pause for like .2 seconds, if no other tap occurs, do Macro A
  2. If another tap occurs, wait .2 seconds, if no other tap occurs, do Macro B,
  3. Wait .2 seconds, if no other tap occurs, do Macro C

Thanks!

There is no one valid time.

Currently, the defaults for the down time is [NSEvent doubleClickInterval] and the up time defaults to twice that, and they can be configured with private preferences as described in the manual.

Currently there is no function to return [NSEvent doubleClickInterval], though that is on the todo list, but you could use some other way to determine that value (such as via JXA). This value is adjustable in the system preferences.

So in theory the correct pause would be three times that value, but in practice it would have to either be more than that by “enough” to ensure that the second macro really had a chance to execute those various actions required, or you would have to add more logic to the macros to ensure that if the first macro had fired the second one did not run.

Keyboard Maestro is not a real time operating system, so getting the minimum amount of pause without going over is not really going to be possible without a reasonable allowance for variability.

Hey guys,

I made this macro after reading through this thread. I trigger it with Stream Deck buttons and it allows the following for multiple keystrokes:

1 tap = Action A
2 taps = Action B
3 taps or longer press (selected in macro) = Action C

In my case, actions A, B an C output different keystrokes to trigger assignments in nAc, which is the companion app for nOb Control (which I use primarily in Logic Pro).

F Keys Multi-Tap : Long Press.kmmacros (114.8 KB)

It works great and the only things I haven't been able to figure out are:

  • The long press detection seems to have to come first, but it slows down the multi-tap detection. This might be just the way it has to be.
  • If I hold the key beyond the length of time it takes to run through the macro and perform the actions, the trigger keystroke leaks through to Logic Pro and causes a screen-flash error response. Perhaps there's a way to prevent this?
  • F11 and F12 don't seem to work so I've limited it to F1 to F10. There may be some keystroke conflict I'm not aware of, perhaps due to the modifiers being used.
2 Likes

Yes, noticed that. KM doesn’t know if you finished, so it needs to wait for the long press first.
Thanks for sharing!

1 Like

Okay, I like this, but suppose I want the Long Press key to be the letter "j" and it will trigger an action if I leave it press for .5 seconds, otherwise it would just type the letter "j"? I tried it and it didn't work.

Can't be done reliably.

Period.

I don't know about the current version of the engine, but when I first started using KM, I had managed to get it to work. But only in certain circumstances, and I was never sure what those circumstances were. Which is why I said "reliably". :joy: