Assigning multiple actions to a key

I want the caps lock key to be escape in single press, change later on double but be a layer switcher on holding the key.

Is this possible? Reading into the smart macros docs sounds like it is but confused on it all

1 Like

Well, I guess following may work?

ifSecondary final holdLayer mod                 // hold with another key
ifGesture $thisKeyId final holdKey capsLock     // doubletap behavior
holdKey escape                                  // the single tap behavior

But yes, there is currently no syntax for distinguishing taps from holds…

2 Likes

Would be nice if the agent allowed configuring these different types of holds such as the double tap, and/or tap and then hold (similar to other keyboard agent’s), where we can also choose the sensitivity via a slider.

I found what you listed does work, but the sensitivity for the single tap behaviour has a bit of lag.

The biggest part of the lag is probably caused by the ifGesture, which if I am not mistaken has default timeout of 500. You can shorten it with timeoutIn ... parameter.

E.g., ifGesture timeoutIn 200 $thisKeyId final holdKey capsLock

1 Like

sorry to hijack — but any idea why the oneshot in the below would not work please?

ifSecondary final holdKey iLS-                  // hold with another key
ifGesture timeoutIn 200 $thisKeyId goTo caps		    // doubletap behavior
oneShot holdKey iLS- // the single tap behavior
break
caps: 
pressKey capsLock
delayUntil 400
releaseKey capsLock

Please, reduce it to a minimal example.

This works fine for me:

ifSecondary final holdKey a                  // hold with another key
ifGesture timeoutIn 200 $thisKeyId final holdKey b		    // doubletap behavior
oneShot holdKey iLS- // the single tap behavior

(Note that in the last release a timeout was added for oneShot - 500ms by default.)

2 Likes

Sorry Karel, noted for future posts.

Yes, it was the timeout that was getting me.

Thanks

1 Like

You really rocks @kareltucek , I built two macros to get this funcionality two months ago, using variables and ifSecondary, but I didn’t realize that you can achieve it, using just three lines of code. I must say thank you.

1 Like

I second that @kareltucek really rocks! Thank you all so much, this is so good. The following code is what I ended up using:

ifSecondary final holdLayer mouse                           // mouse layer if long press
ifGesture timeoutIn 150 $thisKeyId final holdKey capsLock   // doubletap behavior (??)
oneShot holdKey escape                                      // the single tap behavior

Now the CapsLock button is an Esc when pressed short (I found 200 to be a bit slow so I adjusted it down to 150), and the Mouse layer when long pressed. I’m not sure why the doubletap behavior isn’t working for me (probably because the timeoutIn is set too fast, but I couldn’t get it to work with 200 either), but it doesn’t matter as I rarely use Caps Lock to begin with.

@doyoon Works fine for me. Please share your UserConfig if you want me to look into it.

I am curious: Why oneShot holdKey escape and not just tapKey escape?