Toggle layer (e.g. Mouse, Fn, Mod), but not when holding

I think it could be extremely user-friendly when there would be an option to toggle a layer on/off with a key-press, but when holding the key down it will not toggle, but just activate the layer while the key is hold down. In Agent I see no way if/ how I can achieve that.

Reason is that with this behavior a layer-key will still allow to activate a layer by holding it down, but will not need a double press to activate it, so this solution would have no downsides in my book, but only advantages compared to the current solution, right? [1 ] This would also ease very much to have a layer-key only on one side of the keyboard, but still allowing to press the keys ergonomically correct without chording [only needing an additional keypress after the “action” happening on the same side like the layer-key. Would still be sufficient for not that often used keys]!

[1] One can argue that this might be more prone to accidental activating a layer, so the current approach might still be preferred by some?

1 Like

You can achieve that with an extended macro. Something like this:

holdLayer mod
ifInterrupted break
ifPlaytime 300 break
toggleLayer mod

As long as you hold the key it will be Layer “mod”. If you press another key, you’ll get actions from that layer as long as you keep holding the layer switch key.
If you hold it down for more than 300ms it also continues to work as a Layer hold.
If you briefly tap it (less than 300ms), it toggles the Layer. (If you don’t want the 300ms timeout for tapping, just remove that line.)

On the target layer (in this case, the mod layer), map a corresponding untoggle macro to the same button:

holdLayer previous
ifInterrupted break
ifPlaytime 300 break



This is so cool. Thanks a lot! I tried it and it works great and allows to toggle between two layers in that way. That can surely be handy for some use cases.
I wanted a little bit different behaviour for my use case, so that when you are in the new layer you also can hold and later let go the key and then will get back to the base layer again. This way it is always “safe” to keep the key hold-down and to be sure you can use the functions on the key and that you will get back to the base layer as soon as you release the key. So because I do not know yet where to look in which of the three macro documentation places I just guessed how the command could look like. And that turned out to be working as I wanted. :slight_smile:

I have a combined mouse and media consumption layer where this comes in super handy. So now I have for my lower left cluster key the following.

Macro for the base layer:

holdLayer mouse
ifInterrupted break
ifPlaytime 300 break
toggleLayer mouse

Macro for the target (in that case mouse) layer:

holdLayer mouse
toggleLayer base

Welcome. Karl’s macro engine is pretty cool, and can do almost anything; but it’s hard to understand how to control it. We really need some good examples. Maybe a Wiki to collect them?

In your second macro, what happens if you change the toggleLayer base to unToggleLayer? Each toggleLayer pushes another layer onto the layer stack, so I think you really want to go down the stack to the previous (base) layer here!

Thanks, unToggleLayer works as well. Can I see that as a stack which is changed and layers pushed to or popped of the stack? Then unToggleLayer is the better and cleaner approach.

A collection of sample macros would indeed be great.

P.S.: Maybe you have noticed my nickname. :wink:

Yes, the nickname. Definitely you know how a stack works. :wink:

Just created a wiki in the firmware repo, but I’m unsure how well it works regarding collaboration. Let’s give it a try. We can use something else if it doesn’t work out.