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

I still suspect it's more to do with your mac, as I'm hammering out "jeep" and "jjjjjjjjjj" at break-neck speed without issue... And I'm a drummer. :joy:

As part of detecting the press and release of the "J" key in a standalone macro.

The trouble is, KM "eats" the keypress , so if you want to use J as a hotkey and type J at the same time, you have to simulate pressing "J" as part of the macro.

KM would already have to be aware of the keypress, so J has to be the hotkey. See what I mean?

If you can think of a better solution, I'm all ears.

While a drummer writes "jeep", I bought one long ago. :joy: :rofl: :innocent:

Seriously, your macro is very useful for keys that are not needed in daily writing in rapid succession.

I'd be interested to know whether it works for other people or they get the same result as you.

Mh … What I do not understand. When I press the letter "a" normally while writing, the system makes an "a". Of course, what else? The "a" is typed when the key is down, not up (released).

If I press "a" and hold it, this menu appears
image

Isn't this exactly the same short/long press action? Why does this work here without interference?

Good point!

Hey Frank,

This is the accent menu in macOS that Apple so kindly added and didn't provide a proper system preference for.

Older versions of macOS:

defaults write -g ApplePressAndHoldEnabled -bool true

Newer versions of macOS:

Accents off:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

Accents back on:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool true

Accents do not play nice with single-key long press triggers in Keyboard Maestro.

-Chris

3 Likes

Hi @ccstone, thanks a lot, I disabled this a long time ago because I don't need it (and it is annoying). But that does not help here.

Single key short/long press actually doesn't work at all - unfortunately. Not for people who can write fast. The reason is clear: if one letter is typed on release and the next on pressed, it can't work.

The question is: Why does macos manage it with its "bubbles"? "a" is written on down (short press). If the key is held longer (long press), the "bubble" appears. This is perfect short/long press behavior, which apparently no other software manages :man_shrugging:

The forum has several examples of short press/long press macros that are not dependent upon press/release.

They are dependent upon an actual long-press.

Here is one example:

Ok, I didn't know that, thanks for pointing that out! After a quick look, I have no idea how to use that. Before I get into it. I'm looking for something that doesn't cause delays in writing with a single key trigger. Eg, short press "a" = "a", long press "a" = something else. Do you think this works?

Of course it works!Β  :sunglasses:

Here's a more germane example:

Short-Press - Long-Press Keyboard Shortcut Example v1.00.kmmacros (9.1 KB)
Keyboard Maestro Export

This method isn't perfect, because Keyboard Maestro is listening to the system and emulating key-presses and is not a driver-level utility. Even so – chances are pretty fair that it'll be good enough for your purposes.

If you need something more sophisticated the only thing I know of is Karabiner-Elements – it does run at the driver level.

-Chris

4 Likes

Unfortunately this is not true, dear Chris, the macro you suggested suffers from the same disease as all of its kind. The letters are typed when released, not when pressed.

This leads to the problem I explained in the post above. Example with "j". The macro does not type "jeep", but "ejep". The reason is obvious.

Karabiner Elements does exactly the same (mess). The only way would be to output the letters in the same order as they were typed. Like in a queue, who comes later, stands behind.

I know only one software, which "manages" both actions, short and long, when pressed, so that normal writing is possible. But this is a bug in the software, which I discovered by chance! :rofl: Setting up these actions is very laborious and it is a maintenance nightmare. That's why I'm still looking for other solutions.

I nevertheless thank you very much for your help. :pray: If you think of anything else, I am a grateful listener. :smiley:

Frank

KM can not guess ahead of time. It needs to know if you finished pressing once or twice,hence the need in @ccstone β€˜s macro for a timer.

Yes, that is the standard argumentation. But it is only true if the two actions are connected. That's why I try to separate the actions :smirk:

My apologies for not saying thanks here for explaining this and what it does. I have since finally taken a couple of courses on RegEx and understand it much better. Thanks for the inspiration.

This is such a helpful thread and as I was looking for the answer to this again I saw this very well titled thread that was exactly what I was looking for and notice who the poster wise, it was like he thinks just like me. That has happened so many times and this is a great resource to come back to again and again when I forget what I once knew.

I miss JMichaelTX, It's a great loss; he was an amazing contributor to this forum.

1 Like

And a truly nice guy, even if he and I did have some knock-down arguments. :smile:

Regular expressions are awesome, but IMO the only real way to learn about them in a way that sticks is to use them regularly. I mean, they are regular expressions, after all. :rofl:

As for that explanation, I'm, sure I got it from regex101.com.

This is pretty cool, and yet more learning came with it, especially with the cancel this macro portion. It took me a second to figure out why the typed J wasn't executed.

I am not quite wrapping my head around the semaphore lock and unlock. It is set to 100 millisecond so it would time out before the rest of the macro runs. It seems to work just fine without either of the Semaphore actions but I am sure it is ensuring something good happens that I am not seeing.

I really don't know why the darn Semaphore lock continues to plague my brain and more than I can grasp. I have read the Wiki all the way through again, and multiple places on the forum about it.

Yes, he was a gem with all the people he helped and moved Keyboard Maestro, along with some of his arguments about doing things with Variables and many other things. It's fun seeing multiple smart people develop different ways of doing things. It's usually a great learning experience in how to do things and in kindness and compassion. An area where @DanThomas excels and shines very much! It no doubt has to be difficult working with so many less competent people and still having compassion for so much ignorance, and I mean that sincerely and with love.

2 Likes

I understand, although since I've done multi-threaded programming for many years, it's second nature to me, so sometimes it's hard to explain.

I asked ChatGPT, and here's a great answer:

Semaphore Analogy: A Bathroom with One Stall

Imagine a public bathroom with just one stall:

  • When someone enters the stall, they lock the door.
  • The lock acts as a signal: "This stall is occupied. Wait your turn."
  • When the person finishes, they unlock the door, signaling that the stall is free for the next person.

So a semaphore with a timeout of zero means you come into the bathroom, see the door is locked, and turn around and leave.

A semaphore with a timeout just specifies how long you're willing to wait.

Let's start with that, and see if it helps. There's more nuance to it in the case of @ccstone's example, but we can address that once you understand this principal.

3 Likes

ChatGPT's analogy was crappy (little potty joke, trying to stick with the theme :wink:). Yes, that makes perfect sense and a very good analogy. Many of the things stated on the Wiki make sense as well.

Pairing up the names and how they interact within (as in the case of @ccstone macro) and with other macros sometimes illudes me. I think if there were a bundle of example macros that could be included on the Wiki as appropriate I would understand many of the use case scenarios.

I have used semaphore locks when I didn't need to because the macro actions wait for others to finish and are sequential, and triggering sub-macros only happens after the sub-macros finish.

I hope I am not derailing the thread too much here. I would love to understand the use case in @ccstone macro and what it was included for since it seems to work without them, and I am not making sense of them.

Love the crappy joke - right up my alley (cringe).

Yeah, I get it. My nephew is one of those people who are so smart they can't understand how the rest of us don't just "get it". There have been many times I wished I could just download his knowledge into my brain. So likewise, I wish I could just "dump" my knowledge into yours.

Sheesh, I'm 68 and still love toilet humor.

image

That would be sweet. If that were possible, think of where we would be as a society. It sounds like the storyline for a sweet fiction movie. If you don't already, you might consider authoring books.