forked from kofal.net/zmk
feat(behaviors): Add macro support.
* Fine grainted press/release/tap actions. * TIming between actions can be controlled. * Processed async, to avoid blocking.
This commit is contained in:
committed by
Pete Johanson
parent
58c7c0ee0c
commit
3a6a249ad0
2
app/tests/macros/basic/events.patterns
Normal file
2
app/tests/macros/basic/events.patterns
Normal file
@@ -0,0 +1,2 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*behavior_queue_process_next/queue_process_next/p
|
||||
18
app/tests/macros/basic/keycode_events.snapshot
Normal file
18
app/tests/macros/basic/keycode_events.snapshot
Normal file
@@ -0,0 +1,18 @@
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
14
app/tests/macros/basic/native_posix.keymap
Normal file
14
app/tests/macros/basic/native_posix.keymap
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
#include "../behavior_keymap.dtsi"
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1000)>;
|
||||
};
|
||||
68
app/tests/macros/behavior_keymap.dtsi
Normal file
68
app/tests/macros/behavior_keymap.dtsi
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
/ {
|
||||
macros {
|
||||
ZMK_MACRO(abc_macro,
|
||||
wait-ms = <10>;
|
||||
tap-ms = <50>;
|
||||
bindings = <&kp A &kp B &kp C>;
|
||||
)
|
||||
|
||||
ZMK_MACRO(hold_shift_macro,
|
||||
bindings
|
||||
= <¯o_press &kp LSHFT>
|
||||
, <¯o_tap>
|
||||
, <&kp D &kp O &kp G>
|
||||
, <¯o_release &kp LSHFT>
|
||||
;
|
||||
)
|
||||
|
||||
ZMK_MACRO(custom_timing,
|
||||
bindings
|
||||
= <¯o_wait_time 50>
|
||||
, <&kp A>
|
||||
, <¯o_tap_time 20>
|
||||
, <&kp B &kp C>
|
||||
;
|
||||
)
|
||||
|
||||
ZMK_MACRO(dual_sequence_macro,
|
||||
wait-ms = <10>;
|
||||
tap-ms = <40>;
|
||||
bindings
|
||||
= <¯o_press &kp LALT>
|
||||
, <¯o_tap>
|
||||
, <&kp TAB>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &kp LALT>
|
||||
;
|
||||
)
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&abc_macro &mo 1
|
||||
&hold_shift_macro &custom_timing>;
|
||||
};
|
||||
|
||||
extra_layer {
|
||||
bindings = <
|
||||
&dual_sequence_macro &trans
|
||||
&kp TAB &none>;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
@@ -0,0 +1,4 @@
|
||||
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
/ {
|
||||
macros {
|
||||
ZMK_MACRO(
|
||||
mo_mod_macro,
|
||||
wait-ms = <0>;
|
||||
tap-ms = <20>;
|
||||
bindings
|
||||
= <¯o_press &mo 1 &kp LSHFT>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &mo 1 &kp LSHFT>;
|
||||
)
|
||||
};
|
||||
|
||||
behaviors {
|
||||
mth: macro_tap_hold {
|
||||
compatible = "zmk,behavior-hold-tap";
|
||||
label = "MACRO_TAP_HOLD";
|
||||
#binding-cells = <2>;
|
||||
flavor = "tap-unless-interrupted";
|
||||
tapping-term-ms = <200>;
|
||||
bindings = <&mo_mod_macro>, <&kp>;
|
||||
};
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&mth 0 TAB &kp A
|
||||
&kp B &kp C>;
|
||||
};
|
||||
|
||||
extra_layer {
|
||||
bindings = <
|
||||
&kp D &kp E
|
||||
&kp F &kp G>;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>;
|
||||
};
|
||||
1
app/tests/macros/mo-plus-modifier-macro/events.patterns
Normal file
1
app/tests/macros/mo-plus-modifier-macro/events.patterns
Normal file
@@ -0,0 +1 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
@@ -0,0 +1,4 @@
|
||||
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
46
app/tests/macros/mo-plus-modifier-macro/native_posix.keymap
Normal file
46
app/tests/macros/mo-plus-modifier-macro/native_posix.keymap
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
/ {
|
||||
macros {
|
||||
ZMK_MACRO(
|
||||
mo_mod_macro,
|
||||
wait-ms = <0>;
|
||||
tap-ms = <20>;
|
||||
bindings
|
||||
= <¯o_press &mo 1 &kp LSHFT>
|
||||
, <¯o_pause_for_release>
|
||||
, <¯o_release &mo 1 &kp LSHFT>;
|
||||
)
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&mo_mod_macro &kp A
|
||||
&kp B &kp C>;
|
||||
};
|
||||
|
||||
extra_layer {
|
||||
bindings = <
|
||||
&kp D &kp E
|
||||
&kp F &kp G>;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>;
|
||||
};
|
||||
2
app/tests/macros/press-mid-macro/events.patterns
Normal file
2
app/tests/macros/press-mid-macro/events.patterns
Normal file
@@ -0,0 +1,2 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*keymap_apply_position_state/pos_state/p
|
||||
10
app/tests/macros/press-mid-macro/keycode_events.snapshot
Normal file
10
app/tests/macros/press-mid-macro/keycode_events.snapshot
Normal file
@@ -0,0 +1,10 @@
|
||||
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
|
||||
pos_state: layer: 0 position: 1, binding name: MO
|
||||
pos_state: layer: 0 position: 1, binding name: MO
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
14
app/tests/macros/press-mid-macro/native_posix.keymap
Normal file
14
app/tests/macros/press-mid-macro/native_posix.keymap
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
#include "../behavior_keymap.dtsi"
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,1000)>;
|
||||
};
|
||||
1
app/tests/macros/press-release/events.patterns
Normal file
1
app/tests/macros/press-release/events.patterns
Normal file
@@ -0,0 +1 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
8
app/tests/macros/press-release/keycode_events.snapshot
Normal file
8
app/tests/macros/press-release/keycode_events.snapshot
Normal file
@@ -0,0 +1,8 @@
|
||||
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
|
||||
14
app/tests/macros/press-release/native_posix.keymap
Normal file
14
app/tests/macros/press-release/native_posix.keymap
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
#include "../behavior_keymap.dtsi"
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,1000)>;
|
||||
};
|
||||
2
app/tests/macros/timing-override/events.patterns
Normal file
2
app/tests/macros/timing-override/events.patterns
Normal file
@@ -0,0 +1,2 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*behavior_queue_process_next/queue_process_next/p
|
||||
18
app/tests/macros/timing-override/keycode_events.snapshot
Normal file
18
app/tests/macros/timing-override/keycode_events.snapshot
Normal file
@@ -0,0 +1,18 @@
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 100ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 20ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 20ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 50ms
|
||||
14
app/tests/macros/timing-override/native_posix.keymap
Normal file
14
app/tests/macros/timing-override/native_posix.keymap
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
#include "../behavior_keymap.dtsi"
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(1,1,10) ZMK_MOCK_RELEASE(1,1,750)>;
|
||||
};
|
||||
3
app/tests/macros/wait-macro-release/events.patterns
Normal file
3
app/tests/macros/wait-macro-release/events.patterns
Normal file
@@ -0,0 +1,3 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
s/.*behavior_queue_process_next/queue_process_next/p
|
||||
s/.*queue_macro/qm/p
|
||||
16
app/tests/macros/wait-macro-release/keycode_events.snapshot
Normal file
16
app/tests/macros/wait-macro-release/keycode_events.snapshot
Normal file
@@ -0,0 +1,16 @@
|
||||
qm: Iterating macro bindings - starting: 0, count: 4
|
||||
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 40ms
|
||||
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 10ms
|
||||
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
|
||||
qm: Iterating macro bindings - starting: 5, count: 2
|
||||
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
|
||||
kp_released: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
|
||||
queue_process_next: Processing next queued behavior in 0ms
|
||||
14
app/tests/macros/wait-macro-release/native_posix.keymap
Normal file
14
app/tests/macros/wait-macro-release/native_posix.keymap
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
#include "../behavior_keymap.dtsi"
|
||||
|
||||
&kscan {
|
||||
events = <ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_PRESS(1,0,400) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,1000) ZMK_MOCK_RELEASE(0,1,1000)>;
|
||||
};
|
||||
Reference in New Issue
Block a user