From 54dabffd0d371595a8142ee4da4f5d888a310cda Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 9 Jun 2021 06:10:20 +0000 Subject: [PATCH] feat(behaviors): Add caps word (`&caps_word`). * Add new `&caps_word` behavior that acts like caps lock, but releases automatically when any "break" keycode is pressed. --- app/CMakeLists.txt | 1 + app/dts/behaviors.dtsi | 1 + app/dts/behaviors/caps_word.dtsi | 19 ++ .../behaviors/zmk,behavior-caps-word.yaml | 15 ++ app/src/behaviors/behavior_caps_word.c | 186 ++++++++++++++++++ app/tests/caps-word/behavior_keymap.dtsi | 17 ++ .../events.patterns | 4 + .../keycode_events.snapshot | 17 ++ .../native_posix.keymap | 21 ++ .../events.patterns | 4 + .../keycode_events.snapshot | 14 ++ .../native_posix.keymap | 21 ++ .../events.patterns | 3 + .../keycode_events.snapshot | 13 ++ .../native_posix.keymap | 17 ++ .../events.patterns | 3 + .../keycode_events.snapshot | 9 + .../native_posix.keymap | 17 ++ docs/docs/behaviors/caps-word.md | 74 +++++++ docs/sidebars.js | 1 + 20 files changed, 457 insertions(+) create mode 100644 app/dts/behaviors/caps_word.dtsi create mode 100644 app/dts/bindings/behaviors/zmk,behavior-caps-word.yaml create mode 100644 app/src/behaviors/behavior_caps_word.c create mode 100644 app/tests/caps-word/behavior_keymap.dtsi create mode 100644 app/tests/caps-word/continue-with-non-alpha-continue-list-item/events.patterns create mode 100644 app/tests/caps-word/continue-with-non-alpha-continue-list-item/keycode_events.snapshot create mode 100644 app/tests/caps-word/continue-with-non-alpha-continue-list-item/native_posix.keymap create mode 100644 app/tests/caps-word/continue-with-non-modified-numeric-usage-id/events.patterns create mode 100644 app/tests/caps-word/continue-with-non-modified-numeric-usage-id/keycode_events.snapshot create mode 100644 app/tests/caps-word/continue-with-non-modified-numeric-usage-id/native_posix.keymap create mode 100644 app/tests/caps-word/deactivate-by-non-alpha-non-continuation/events.patterns create mode 100644 app/tests/caps-word/deactivate-by-non-alpha-non-continuation/keycode_events.snapshot create mode 100644 app/tests/caps-word/deactivate-by-non-alpha-non-continuation/native_posix.keymap create mode 100644 app/tests/caps-word/deactivate-by-second-press/events.patterns create mode 100644 app/tests/caps-word/deactivate-by-second-press/keycode_events.snapshot create mode 100644 app/tests/caps-word/deactivate-by-second-press/native_posix.keymap create mode 100644 docs/docs/behaviors/caps-word.md diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 9c7befec..970c6c20 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -47,6 +47,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c) target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c) + target_sources(app PRIVATE src/behaviors/behavior_caps_word.c) target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c) target_sources(app PRIVATE src/behaviors/behavior_mod_morph.c) target_sources(app PRIVATE src/behaviors/behavior_outputs.c) diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 4333ceea..5b5f72b4 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -14,3 +14,4 @@ #include #include #include +#include diff --git a/app/dts/behaviors/caps_word.dtsi b/app/dts/behaviors/caps_word.dtsi new file mode 100644 index 00000000..57d5cab7 --- /dev/null +++ b/app/dts/behaviors/caps_word.dtsi @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + behaviors { + /omit-if-no-ref/ caps_word: behavior_caps_word { + compatible = "zmk,behavior-caps-word"; + label = "CAPS_WORD"; + #binding-cells = <0>; + continue-list = ; + }; + }; +}; + diff --git a/app/dts/bindings/behaviors/zmk,behavior-caps-word.yaml b/app/dts/bindings/behaviors/zmk,behavior-caps-word.yaml new file mode 100644 index 00000000..cc1dda01 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-caps-word.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2021 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Caps word behavior + +compatible: "zmk,behavior-caps-word" + +include: zero_param.yaml + +properties: + continue-list: + type: array + required: true + mods: + type: int diff --git a/app/src/behaviors/behavior_caps_word.c b/app/src/behaviors/behavior_caps_word.c new file mode 100644 index 00000000..45e3d9d9 --- /dev/null +++ b/app/src/behaviors/behavior_caps_word.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_caps_word + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + +struct caps_word_continue_item { + uint16_t page; + uint32_t id; + uint8_t implicit_modifiers; +}; + +struct behavior_caps_word_config { + zmk_mod_flags_t mods; + uint8_t index; + uint8_t continuations_count; + struct caps_word_continue_item continuations[]; +}; + +struct behavior_caps_word_data { + bool active; +}; + +static void activate_caps_word(const struct device *dev) { + struct behavior_caps_word_data *data = dev->data; + + data->active = true; +} + +static void deactivate_caps_word(const struct device *dev) { + struct behavior_caps_word_data *data = dev->data; + + data->active = false; +} + +static int on_caps_word_binding_pressed(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = device_get_binding(binding->behavior_dev); + struct behavior_caps_word_data *data = dev->data; + + if (data->active) { + deactivate_caps_word(dev); + } else { + activate_caps_word(dev); + } + + return ZMK_BEHAVIOR_OPAQUE; +} + +static int on_caps_word_binding_released(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + return ZMK_BEHAVIOR_OPAQUE; +} + +static const struct behavior_driver_api behavior_caps_word_driver_api = { + .binding_pressed = on_caps_word_binding_pressed, + .binding_released = on_caps_word_binding_released, +}; + +static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh); + +ZMK_LISTENER(behavior_caps_word, caps_word_keycode_state_changed_listener); +ZMK_SUBSCRIPTION(behavior_caps_word, zmk_keycode_state_changed); + +static const struct device *devs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)]; + +static bool caps_word_is_caps_includelist(const struct behavior_caps_word_config *config, + uint16_t usage_page, uint8_t usage_id, + uint8_t implicit_modifiers) { + for (int i = 0; i < config->continuations_count; i++) { + const struct caps_word_continue_item *continuation = &config->continuations[i]; + LOG_DBG("Comparing with 0x%02X - 0x%02X (with implicit mods: 0x%02X)", continuation->page, + continuation->id, continuation->implicit_modifiers); + + if (continuation->page == usage_page && continuation->id == usage_id && + continuation->implicit_modifiers == implicit_modifiers) { + LOG_DBG("Continuing capsword, found included usage: 0x%02X - 0x%02X", usage_page, + usage_id); + return true; + } + } + + return false; +} + +static bool caps_word_is_alpha(uint8_t usage_id) { + return (usage_id >= HID_USAGE_KEY_KEYBOARD_A && usage_id <= HID_USAGE_KEY_KEYBOARD_Z); +} + +static bool caps_word_is_numeric(uint8_t usage_id) { + return (usage_id >= HID_USAGE_KEY_KEYBOARD_1_AND_EXCLAMATION && + usage_id <= HID_USAGE_KEY_KEYBOARD_0_AND_RIGHT_PARENTHESIS); +} + +static void caps_word_enhance_usage(const struct behavior_caps_word_config *config, + struct zmk_keycode_state_changed *ev) { + if (ev->usage_page != HID_USAGE_KEY || !caps_word_is_alpha(ev->keycode)) { + return; + } + + LOG_DBG("Enhancing usage 0x%02X with modifiers: 0x%02X", ev->keycode, config->mods); + ev->implicit_modifiers |= config->mods; +} + +static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh) { + struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh); + if (ev == NULL || !ev->state) { + return ZMK_EV_EVENT_BUBBLE; + } + + for (int i = 0; i < DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT); i++) { + const struct device *dev = devs[i]; + if (dev == NULL) { + continue; + } + + struct behavior_caps_word_data *data = dev->data; + if (!data->active) { + continue; + } + + const struct behavior_caps_word_config *config = dev->config; + + caps_word_enhance_usage(config, ev); + + if (!caps_word_is_alpha(ev->keycode) && !caps_word_is_numeric(ev->keycode) && + !caps_word_is_caps_includelist(config, ev->usage_page, ev->keycode, + ev->implicit_modifiers)) { + LOG_DBG("Deactivating caps_word for 0x%02X - 0x%02X", ev->usage_page, ev->keycode); + deactivate_caps_word(dev); + } + } + + return ZMK_EV_EVENT_BUBBLE; +} + +static int behavior_caps_word_init(const struct device *dev) { + const struct behavior_caps_word_config *config = dev->config; + devs[config->index] = dev; + return 0; +} + +#define CAPS_WORD_LABEL(i, _n) DT_INST_LABEL(i) + +#define PARSE_BREAK(i) \ + {.page = (HID_USAGE_PAGE(i) & 0xFF), \ + .id = HID_USAGE_ID(i), \ + .implicit_modifiers = SELECT_MODS(i)}, + +#define BREAK_ITEM(i, n) PARSE_BREAK(DT_INST_PROP_BY_IDX(n, continue_list, i)) + +#define KP_INST(n) \ + static struct behavior_caps_word_data behavior_caps_word_data_##n = {.active = false}; \ + static struct behavior_caps_word_config behavior_caps_word_config_##n = { \ + .index = n, \ + .mods = DT_INST_PROP_OR(n, mods, MOD_LSFT), \ + .continuations = {UTIL_LISTIFY(DT_INST_PROP_LEN(n, continue_list), BREAK_ITEM, n)}, \ + .continuations_count = DT_INST_PROP_LEN(n, continue_list), \ + }; \ + DEVICE_DT_INST_DEFINE(n, behavior_caps_word_init, device_pm_control_nop, \ + &behavior_caps_word_data_##n, &behavior_caps_word_config_##n, \ + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &behavior_caps_word_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(KP_INST) + +#endif diff --git a/app/tests/caps-word/behavior_keymap.dtsi b/app/tests/caps-word/behavior_keymap.dtsi new file mode 100644 index 00000000..04653bec --- /dev/null +++ b/app/tests/caps-word/behavior_keymap.dtsi @@ -0,0 +1,17 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label = "Default keymap"; + + default_layer { + bindings = < + &caps_word &kp A + &kp N6 &kp MINUS + >; + }; + }; +}; diff --git a/app/tests/caps-word/continue-with-non-alpha-continue-list-item/events.patterns b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/events.patterns new file mode 100644 index 00000000..dd4d3d3f --- /dev/null +++ b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p +s/.*caps_word_is_caps_includelist/caps_includelist/p \ No newline at end of file diff --git a/app/tests/caps-word/continue-with-non-alpha-continue-list-item/keycode_events.snapshot b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/keycode_events.snapshot new file mode 100644 index 00000000..fe705ba4 --- /dev/null +++ b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/keycode_events.snapshot @@ -0,0 +1,17 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +caps_includelist: Comparing with 0x07 - 0x2d (with implicit mods: 0x02) +caps_includelist: Comparing with 0x07 - 0x2d (with implicit mods: 0x00) +caps_includelist: Continuing capsword, found included usage: 0x07 - 0x2d +pressed: usage_page 0x07 keycode 0x2d implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x2d implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/continue-with-non-alpha-continue-list-item/native_posix.keymap b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/native_posix.keymap new file mode 100644 index 00000000..68c3249f --- /dev/null +++ b/app/tests/caps-word/continue-with-non-alpha-continue-list-item/native_posix.keymap @@ -0,0 +1,21 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&caps_word { + continue-list = ; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(1,1,10) + ZMK_MOCK_RELEASE(1,1,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/events.patterns b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/events.patterns new file mode 100644 index 00000000..dd4d3d3f --- /dev/null +++ b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p +s/.*caps_word_is_caps_includelist/caps_includelist/p \ No newline at end of file diff --git a/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/keycode_events.snapshot b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/keycode_events.snapshot new file mode 100644 index 00000000..23ddbe1b --- /dev/null +++ b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/keycode_events.snapshot @@ -0,0 +1,14 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x23 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x23 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/native_posix.keymap b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/native_posix.keymap new file mode 100644 index 00000000..40a4d4a9 --- /dev/null +++ b/app/tests/caps-word/continue-with-non-modified-numeric-usage-id/native_posix.keymap @@ -0,0 +1,21 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&caps_word { + continue-list = ; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/events.patterns b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/events.patterns new file mode 100644 index 00000000..fa75ab0c --- /dev/null +++ b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/keycode_events.snapshot b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/keycode_events.snapshot new file mode 100644 index 00000000..eb24c4bb --- /dev/null +++ b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/keycode_events.snapshot @@ -0,0 +1,13 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x2d implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x2d implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/native_posix.keymap b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/native_posix.keymap new file mode 100644 index 00000000..4219e354 --- /dev/null +++ b/app/tests/caps-word/deactivate-by-non-alpha-non-continuation/native_posix.keymap @@ -0,0 +1,17 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(1,1,10) + ZMK_MOCK_RELEASE(1,1,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-second-press/events.patterns b/app/tests/caps-word/deactivate-by-second-press/events.patterns new file mode 100644 index 00000000..fa75ab0c --- /dev/null +++ b/app/tests/caps-word/deactivate-by-second-press/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-second-press/keycode_events.snapshot b/app/tests/caps-word/deactivate-by-second-press/keycode_events.snapshot new file mode 100644 index 00000000..5181f75b --- /dev/null +++ b/app/tests/caps-word/deactivate-by-second-press/keycode_events.snapshot @@ -0,0 +1,9 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/deactivate-by-second-press/native_posix.keymap b/app/tests/caps-word/deactivate-by-second-press/native_posix.keymap new file mode 100644 index 00000000..05f13fed --- /dev/null +++ b/app/tests/caps-word/deactivate-by-second-press/native_posix.keymap @@ -0,0 +1,17 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/docs/docs/behaviors/caps-word.md b/docs/docs/behaviors/caps-word.md new file mode 100644 index 00000000..ee493741 --- /dev/null +++ b/docs/docs/behaviors/caps-word.md @@ -0,0 +1,74 @@ +--- +title: Caps Word Behavior +sidebar_label: Caps Word +--- + +## Summary + +The caps word behavior behaves similar to a caps lock, but will automatically deactivate when one of the configured "break keycodes" is pressed, or if the caps word key is pressed again. For smaller keyboards, using [mod-taps](/docs/behaviors/mod-tap), this can help avoid repeated alternating holds when typing words in all caps. + +The modifiers are applied only to to the alphabetic (`A` to `Z`) keycodes, to avoid automatically appliying them to numeric values, etc. + +### Behavior Binding + +- Reference: `&caps_word` + +Example: + +``` +&caps_word +``` + +### Configuration + +#### Continue List + +By default, the caps word will remain active when any alphanumeric character or the underscore (`UNDERSCORE`) characters are pressed. Any other keycode sent, +will turn off caps word. If you would like to override this, you can set a new array of keys in the `continue-list` property in your keymap: + +``` +&caps_word { + continue-list = ; +}; + +/ { + keymap { + ... + }; +}; +``` + +#### Applied Modifier(s) + +In addition, if you would like _multiple_ modifiers, instead of just `MOD_LSFT`, you can override the `mods` property: + +``` +&caps_word { + mods = ; +}; + +/ { + keymap { + ... + }; +}; +``` + +### Multiple Caps Breaks + +If you want to use multiple caps breaks with different codes to break the caps, you can add additional caps words instances to use in your keymap: + +``` +/ { + prog_caps: behavior_prog_caps_word { + compatible = "zmk,behavior-caps-word"; + label = "PROG_CAPS"; + #binding-cells = <0>; + continue-list = ; + }; + + keymap { + ... + }; +}; +``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 04389695..38256219 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -27,6 +27,7 @@ module.exports = { "behaviors/mod-morph", "behaviors/sticky-key", "behaviors/sticky-layer", + "behaviors/caps-word", "behaviors/reset", "behaviors/bluetooth", "behaviors/outputs",