urob / zmk-auto-layer

A ZMK module adding an auto-layer behavior
MIT License
15 stars 2 forks source link
zmk zmk-module

ZMK-AUTO-LAYER

This module adds an auto-layer behavior to ZMK. A layer activated by the behavior continues to be active for as long as keys in a configurable continue-list are pressed, and deactivates automatically on any other key press.

This is a re-implementation of PR #1451, separating the auto-layer behavior from caps-word and making the layer index a parameter.

Usage

To load the module, add the following entries to remotes and projects in config/west.yml.

manifest:
  remotes:
    - name: zmkfirmware
      url-base: https://github.com/zmkfirmware
    - name: urob
      url-base: https://github.com/urob
  projects:
    - name: zmk
      remote: zmkfirmware
      revision: main
      import: app/west.yml
    - name: zmk-auto-layer
      remote: urob
      revision: main
  self:
    path: config

Configuration

There are four configuration properties for the behavior:

Behavior instances take one mandatory argument that specifies the index of the layer to be activated.

Example: Num-word

The module pre-configures a num-word behavior instance that activates a layer for as long as only numbers and a few other keys are pressed. To use it, source the definition at the top your keymap:

#include <behaviors/num_word.dtsi>

Then, add &num_word NAV anywhere to your keymap where NAV is the index of your numbers layer.

Customization: By default, num_word continues on number keys as well as on BSPC, DEL, DOT, COMMA, PLUS, MINUS, STAR, FSLH, and EQUAL. To customize the continue-list, overwrite it in the keymap as follows:

&num_word {
  continue-list = <BSPC DEL DOT COMMA>;  // do not continue on PLUS, MINUS, STAR, FSLH, EQUAL
};

Example: General case

Custom behavior instances can be defined using the general auto-layer behavior. The following illustrates how to define a nav-word behavior that continues on arrow keys, PG_UP, PG_DOWN, and all modifiers.

/ {
  behaviors {
    nav_word: nav_word {
      compatible = "zmk,behavior-auto-layer";
      #binding-cells = <1>;
      continue-list = <LEFT DOWN UP RIGHT PG_DN PG_UP>;
      ignore-modifiers;
    };
  };
};

References