This commit is contained in:
marcoster 2023-04-20 22:06:06 +00:00 committed by GitHub
commit d99bb9eee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 137 additions and 1 deletions

View file

@ -39,6 +39,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE src/hid.c)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c)
target_sources(app PRIVATE src/behaviors/behavior_key_tap.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)

View file

@ -1,5 +1,6 @@
#include <behaviors/key_press.dtsi>
#include <behaviors/key_toggle.dtsi>
#include <behaviors/key_tap.dtsi>
#include <behaviors/transparent.dtsi>
#include <behaviors/none.dtsi>
#include <behaviors/mod_tap.dtsi>
@ -18,4 +19,4 @@
#include <behaviors/caps_word.dtsi>
#include <behaviors/key_repeat.dtsi>
#include <behaviors/backlight.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/macros.dtsi>

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
/ {
behaviors {
/omit-if-no-ref/ kt: behavior_key_tap {
compatible = "zmk,behavior-key-tap";
label = "KEY_TAP";
#binding-cells = <1>;
};
};
};

View file

@ -0,0 +1,8 @@
# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT
description: Key press/immediate release behavior
compatible: "zmk,behavior-key-tap"
include: one_param.yaml

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#define DT_DRV_COMPAT zmk_behavior_key_tap
#include <device.h>
#include <drivers/behavior.h>
#include <logging/log.h>
#include <zmk/event_manager.h>
#include <zmk/events/keycode_state_changed.h>
#include <zmk/behavior.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_key_tap_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
int ret = ZMK_EVENT_RAISE(
zmk_keycode_state_changed_from_encoded(binding->param1, true, event.timestamp));
if (ret != 0) {
return ret;
}
return ZMK_EVENT_RAISE(
zmk_keycode_state_changed_from_encoded(binding->param1, false, event.timestamp));
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
return 0;
}
static const struct behavior_driver_api behavior_key_tap_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
#define KT_INST(n) \
DEVICE_DT_INST_DEFINE(n, behavior_key_tap_init, device_pm_control_nop, NULL, NULL, \
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_key_tap_driver_api);
DT_INST_FOREACH_STATUS_OKAY(KT_INST)

View file

@ -0,0 +1,17 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
/ {
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&kt LBRC &kt LBKT
&none &none
>;
};
};
};

View file

@ -0,0 +1 @@
s/.*hid_listener_keycode_//p

View file

@ -0,0 +1,4 @@
pressed: usage_page 0x07 keycode 0x2f implicit_mods 0x02 explicit_mods 0x00
released: usage_page 0x07 keycode 0x2f implicit_mods 0x02 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x2f implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x2f implicit_mods 0x00 explicit_mods 0x00

View file

@ -0,0 +1,10 @@
#include "../behavior_keymap.dtsi"
&kscan {
events = <
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(0,0,10)
ZMK_MOCK_RELEASE(0,1,10)
>;
};

View file

@ -0,0 +1,31 @@
---
title: Key Tap Behavior
sidebar_label: Key Tap
---
## Summary
The key tap behavior is similar to [key press](key-press.md), but key tap will press _and then immediately release_ the key (even if the physical key remains held down).
All [keycodes](../codes/index.mdx) (including modifiers) can be used the same way as with the [key press](key-press.md) behavior.
:::tip
Key tap is useful if you experience issues when rolling keys that share a base keycode.
For example, a common programming bigram is `+=`. Behind the scenes, `+` is produced with `SHIFT` and `=`. So typing the keys `+` and `=` too quickly can sometimes result in one of them being ignored since the base-key is still pressed. However, by immediately releasing the key with key tap this issue is circumvented.
See [zmkfirmware/zmk #1076](https://github.com/zmkfirmware/zmk/issues/1076) for a thread tracking this.
:::
### Behavior Binding
- Reference: `&kt`
- Parameter: The keycode usage ID from the usage page, e.g. `PLUS` or `A`
Example:
```
&kt LBKT
```

View file

@ -35,6 +35,7 @@ module.exports = {
"behaviors/tap-dance",
"behaviors/caps-word",
"behaviors/key-repeat",
"behaviors/key-tap",
"behaviors/reset",
"behaviors/bluetooth",
"behaviors/outputs",