Keyboard: Combine Long Hold & Quick Release Actions

Hi,

in theory (at least in my mind) the configured action should trigger a "D" when I press & release the D-key for a short time and trigger a "CMD" when I hold the key for a longer time.

In reality this action triggers repetitive "CMD + D"s when I hold the D-key down.

Does anyone have an idea on how to fix this? I am trying to migrate my "Home Row Mod" (HRM) Setup from Karabiner to BTT. HRM sets modifier keys to the ASDF & JKLÖ Keys when you long hold them. See: A guide to home row mods

Thanks & have a great day,
Volker

ah this is a bit special, I added some specific handling for such setups in 6.1101

@Volker I'm very interested in your results. If you manage to set up a working HRM with BTT, I'd love to replicate it.

I’ve tried this several times, but I’ve always failed. In the end, the problem is always the same: A key can trigger something when it’s pressed or when it’s released. Karabiner allows for a kind of “fine-tuning” that BTT can’t do, as far as I know.

Anyway, when you type the letter “D” it’s typed on release. If a letter follows “D” that is typed when the key is pressed (for example, “U” which isn’t in the HR), then “ud” is typed instead of “du”. Especially if you can type quickly.

If you can solve this problem, you’ll be my hero :slight_smile:

@Frank1 I have something coming up for you soon! I can’t yet promise whether it will work perfectly (it does for me, but it is really complex) but it will be the best that is possible at the level BTT works at.

That sounds very promising. Is it this “queue” feature, which you actually didn’t want to implement because it requires a lot of work?

Actually, this isn't a BTT issue. Karabiner can't do it either, even though some people occasionally claim it can.

A system like this can only work reliably if an app can read my mind or:

If all letters are typed when the key is released (short press). But of course, that leads to a noticeable delay when typing, which isn’t ideal.

The other option is to always type a letter first (on key down) and then delete it if the key is held down longer to trigger the second function. However, this can cause problems in non-text fields.

Maybe you see something I’m missing. In any case, I’m really looking forward to that :slight_smile:

yes there will always be a slight delay while “waiting”, I think this can not really be prevented, but I’ll make the delay / wait configurable

Okay, but isn't that already possible?

If the letter “D” is typed on release and “U” is typed normally, you can insert a delay before the ‘U’ to give the “D” enough time to be typed. The result is (sometimes) “du” instead of “ud.”

A better solution (in my opinion), though probably not feasible, would be for BTT to stop typing the “U” because BTT knows that “D” takes longer to be typed.

BTT knows this because “D” is set up the way it is.

This way, there’s no need for a delay that would have to be “configured”. BTT types as fast as possible, but never types the “U” before the “D”.

Or, more generally: If a letter (key up) is followed by a letter (key down), then the first letter is always typed first.

@Frank1 yes, that's exactly what the new implementation does. It's the "queue" you describe, and there's no fixed delay in it.

When you press D, BTT holds back everything you type until it knows whether D is a tap or a hold. Then it sends it all in the order you typed it. Like you said: as fast as possible, but never the U before the D.

The delay before U in your screenshot is a guess. Too short and you still get "ud", too long and every U lags. You'd also need one for every letter that can follow a home row key. The queue waits exactly as long as it has to:

  • Roll from D to U (you let go of D first): "du" is typed the moment you release D.

  • Hold D and tap U (you let go of U first): ⌘U, without waiting for the hold time.

  • Hold D alone for longer than the hold time: ⌘.

  • Keys that don't come right after a home row key aren't delayed at all.

The "configurable delay" I mentioned earlier is really the hold time: how long you have to hold D before it counts as ⌘ (default 200 ms). It doesn't add a pause to your typing.

The one wait that's left is the one you described yourself. BTT can't read your mind, so the D appears when you release it instead of when you press it. To get rid of even that, "Plain key while typing" (new option) is on by default (150 ms): a home row key pressed right after another key types immediately, because in the middle of a word you almost never want a modifier.

So it's neither of your two options (type everything on release, or type and delete again). Only home row keys wait, only while BTT doesn't know yet, and nothing ever gets deleted.

It'll be in [VERSION] under Settings → Keyboard → Tap-hold keys (home row mods). Each keyboard shortcut also gets a "Tap or hold, keep typing order" option that does the same for any BTT action on long press, for example "ä" on a long A.

(the home row is just an example it will also work with any other BTT action - I guess best wait until I release the first build!)

What can I say? This is brilliant!

BTT can't read my mind. But you obviously can. You've built exactly what's always worked in my head.

Once again, BTT is way ahead of all other apps.

lets wait, currently still an experiment:-)

Wow, I like the discussions my post has triggered and really looking forward to what Andreas is cooking. :heart_eyes::flexed_biceps:

Usually I use my external, mechanical keyboard to type. At the firmware of this keyboard you can deeply configure how the HRM work and (in theory) adjust the timing for each finger separately. Believe me you can easily spend hours configuring :see_no_evil_monkey::sweat_smile:

I am so used to the HRM concept that I even use it with the internal keyboard and karabiner-elements script that only works for the built-in-keyboard of my MacBook (karabiner has a condition for that).

As you described Frank, karabiner is not perfect - but also the mechanical keyboard has here and there some false keystrokes.

Thanks Andreas for the quick-fix - a first look seems to work. Now I'll need to configure it. I'll keep you posted, Frank.

PS: Andreas, congratulations for reaching more than 1000 versions of BTT this year. Amazing!

Have a great evening.

Volker

@Andreas_Hegenberg Let's set aside the home-row concept. That is just a modifier concept with different keys for the modifiers. But it's still a two-key system.

Much more interesting (to me) is short/long press. So, a single-key trigger system. Until now, this was impractical for the reasons mentioned.

Am I correct in understanding that this new BTT feature allows for a “mixed keyboard”? Meaning some keys have a dual function (letter / something else), while others only type the letter.

And despite this mixed dual-function setup, it should be possible to type fast without letter mix-ups or annoying delays?

That would be a revolution!

you can now try it in 6.1103 (uploading)

You need to enable this option for every key that shall be used like this. If no "Short Press" action is defined, it will automatically pass through the original key. So only setting the long press action should suffice.

For the home row concept there are separate settings that should make this easy to setup

All pretty experimental!

Note: this will not work while secure input mode is active, e.g. in password fields.

That's really crazy! It works just as it should. Of course, I haven't been able to test it extensively yet, but it's enough (for now) to realize that what didn't work before is working now. No letter mix-ups.

That’s more than great, Andreas!!!!

I’d like to understand how this works. Could it be that BTT registers a letter typed on release the moment the key is pressed? Then BTT waits for the next letter and moves it to the end of the queue?

@Frank1 yes, that's pretty much it! As soon as you press a key that has a long press action, BTT doesn't know yet whether it will be a short or a long press. So it holds back that key and everything you type after it. As soon as it knows, it sends everything in exactly the order you typed it.

It knows as soon as one of these happens:

  • you release the key → short press
  • you press another key → short press (this is why fast typing isn't slowed down)
  • you keep holding it for the hold time → long press

So nothing gets reordered, it's just held back for a moment and then sent in the original order.

Wow thank you very much Andreas.

Is there any chance to make the HRM configurable (on/off is sufficient) per keyboard:

  • Built-In Keyboard: ON
  • External Keyboard: OFF

would be sufficient for me - that's what karabiner provides.

I added a keyboard option for HRM in 6.1104

Very nice - thank you Andreas.

Does this setting have the same effect? So, if recorded with built-in keyboard it only affects the built-in keyboard and same for external keyboards?

kind of, yes. It allows you to define different shortcuts for different keyboards

Thanks for your explanation, Andreas.

On another note: I just noticed that the old short/long press method (manual time settings for min. and max. hold time) apparently isn’t integrated into the new system. Is there any reason not to use the same mechanism?

This would allow triggering multiple actions in sequence:

1. short press (down/up) Aktion 1

2. long press (down and hold), Action 2 (up)

3. long press (down and hold), Action 2 (hold), Action 3 (up)