Behaviours: add key-tap behavior
This is a solution for keys that use the same keycode but different modifiers (see #1076 as an example, also { and [ or ] and } might occur quite often). The new key behavior introduced here is a simple tap that immediately sends a release event, so that a keypress of the same keycode with a different modifier can be detected immediately.
This commit is contained in:
parent
1e8224c296
commit
cb50620f9f
5 changed files with 73 additions and 1 deletions
|
@ -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/hid.c)
|
||||||
target_sources(app PRIVATE src/behaviors/behavior_key_press.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_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_hold_tap.c)
|
||||||
target_sources(app PRIVATE src/behaviors/behavior_sticky_key.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_caps_word.c)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <behaviors/key_press.dtsi>
|
#include <behaviors/key_press.dtsi>
|
||||||
#include <behaviors/key_toggle.dtsi>
|
#include <behaviors/key_toggle.dtsi>
|
||||||
|
#include <behaviors/key_tap.dtsi>
|
||||||
#include <behaviors/transparent.dtsi>
|
#include <behaviors/transparent.dtsi>
|
||||||
#include <behaviors/none.dtsi>
|
#include <behaviors/none.dtsi>
|
||||||
#include <behaviors/mod_tap.dtsi>
|
#include <behaviors/mod_tap.dtsi>
|
||||||
|
@ -18,4 +19,4 @@
|
||||||
#include <behaviors/caps_word.dtsi>
|
#include <behaviors/caps_word.dtsi>
|
||||||
#include <behaviors/key_repeat.dtsi>
|
#include <behaviors/key_repeat.dtsi>
|
||||||
#include <behaviors/backlight.dtsi>
|
#include <behaviors/backlight.dtsi>
|
||||||
#include <behaviors/macros.dtsi>
|
#include <behaviors/macros.dtsi>
|
||||||
|
|
15
app/dts/behaviors/key_tap.dtsi
Normal file
15
app/dts/behaviors/key_tap.dtsi
Normal 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>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
8
app/dts/bindings/behaviors/zmk,behavior-key-tap.yaml
Normal file
8
app/dts/bindings/behaviors/zmk,behavior-key-tap.yaml
Normal 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
|
47
app/src/behaviors/behavior_key_tap.c
Normal file
47
app/src/behaviors/behavior_key_tap.c
Normal 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 = 0;
|
||||||
|
ret = ZMK_EVENT_RAISE(zmk_keycode_state_changed_from_encoded(binding->param1, true, event.timestamp));
|
||||||
|
if(ret != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
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)
|
Loading…
Add table
Reference in a new issue