Skip to content

ZMK custom behavior module for a smart toggle key

License

Notifications You must be signed in to change notification settings

caksoylar/zmk-smart-toggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Toggle Behavior for ZMK

This is a custom behavior module that implements a "smart toggle" key.

The smart toggle behavior is like the key toggle behavior, except instead of pressing the same key to toggle it off, it turns itself off when layer it is on is deactivated or a key besides itself (or ones in an optional positions list) is pressed.

As a simple example, tapping the &hold_ctrl behavior as defined below will keep Ctrl held while the layer it was placed in is active:

    behaviors {
        hold_ctrl: hold_ctrl {
            compatible = "zmk,behavior-smart-toggle";
            #binding-cells = <0>;
            bindings = <&kp LCTRL>, <&none>;
        };
    };

In addition, pressing the same key while the toggle is active can send a different behavior. For example, this allows you to define a single key window switcher (alt-tab/cmd-tab) where the first tap presses Alt and taps Tab, consecutive taps are interpreted as Tab, and pressing another key or deactivating the layer_nav layer releases Alt:

/ {
    behaviors {
        swapper: swapper {
            compatible = "zmk,behavior-smart-toggle";
            #binding-cells = <0>;
            bindings = <&kp LALT>, <&kp TAB>;
            ignored-key-positions = <1>;
        };

        /* ...other behaviors... */
    };

    keymap {
        compatible = "zmk,keymap";

        /* ...other layers... */

        layer_nav {
            bindings = <&swapper &kp LS(TAB) /* ... */>;
        };
    };
};

ignored-key-positions = <1>; specifies that the second position on the layer will also not toggle off Alt, so you can use it to go backwards in the window list using Shift+Tab.

(This behavior is colloquially known as the "swapper".)

Important

If you place this behavior on a combo, make sure to include the combo key-positions in ignored-key-positions.

Installation

See ZMK modules documentation for adding this module to your ZMK build.

Acknowledgements

This implementation is a simplified version of the tri-state behavior implemented by Nick Conway in ZMK PR #1366. I used the module-ified version by Dhruvin Shah as well.

The reason I chose to not use it as is is so I can simplify and clean it up the way I prefer it, and thus be able to maintain easier going forward.

Related

About

ZMK custom behavior module for a smart toggle key

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published