Add behavior examples

This commit is contained in:
Cem Aksoylar 2023-09-24 23:22:44 -07:00
parent 39ef16e16b
commit c77fbc5a24

View file

@ -27,10 +27,38 @@ Here's a summary of the various major changes since last time, broken down by th
[aumuell](https://github.com/aumuell), [vrinek](https://github.com/vrinek) and [urob] contributed to improving the behavior of [mod-morphs](../docs/behaviors/mod-morph.md) by masking the triggering modifiers and added `keep-mods` property in [#1412](https://github.com/zmkfirmware/zmk/pull/1412). This unlocks more use cases for mod-morphs, since you are no longer constrained to emitting keycodes that work well with the triggering modifier keycodes.
As an example, you can now define a mod-morph that swaps `;` and `:` so that the former is the shifted version of the latter, which wasn't previously possible:
```dts
col_semi: colon_semicolon {
compatible = "zmk,behavior-mod-morph";
label = "COLON_SEMICOLON";
#binding-cells = <0>;
bindings = <&kp COLON>, <&kp SEMI>;
mods = <(MOD_LSFT|MOD_RSFT)>;
};
```
#### Parameterized macros
[petejohanson] added [macros that can be parameterized](../docs/behaviors/macros.md#parameterized-macros) with one or two parameters in [#1232](https://github.com/zmkfirmware/zmk/pull/1232). This allows users to define macros in a more modular way and is a nice quality-of-life improvement.
As a simple example, you could define a macro that puts any keycode provided between double quotes as below and use it like `&ql_macro A` in your keymap:
```dts
ql_macro: quote_letter_macro {
#binding-cells = <1>;
label = "QUOTE_LETTER";
compatible = "zmk,behavior-macro-one-param";
bindings =
<&kp DQT>,
<&macro_param_1to1 &kp MACRO_PLACEHOLDER>,
<&kp DQT>;
};
```
Please see the documentation page linked above for usage and more examples.
#### Arbitrary behaviors on encoder rotation
[nickconway](https://github.com/nickconway) and [petejohanson] added [sensor rotation behaviors](../docs/behaviors/sensor-rotate.md) to allow invoking arbitrary behaviors from encoders [#1758](https://github.com/zmkfirmware/zmk/pull/1758). Previously encoder rotations could only invoke the key-press behavior `&kp` through the `&inc_dec_kp` binding, whereas now you can define new sensor rotation behaviors to invoke others.