mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 04:55:20 -05:00
feat(behaviors): Support parameterized macros.
* Add two new compatibles for macros that take one or two parameters when bound in a keymap. * Use `¯o_param_1to1`, `¯o_param_1to2`, `¯o_param_2to1`, and `¯o_param_2to2` control entries in the bindings for the macro to have the next binding entry have it's values substituted. Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
This commit is contained in:
committed by
Pete Johanson
parent
e686fce4d9
commit
805dd4a53b
1
app/tests/macros/place-holder-parameters/events.patterns
Normal file
1
app/tests/macros/place-holder-parameters/events.patterns
Normal file
@@ -0,0 +1 @@
|
||||
s/.*hid_listener_keycode/kp/p
|
||||
@@ -0,0 +1,16 @@
|
||||
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_pressed: usage_page 0x07 keycode 0x38 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x38 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 0x34 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x34 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 0x34 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x34 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_pressed: usage_page 0x07 keycode 0x09 implicit_mods 0x00 explicit_mods 0x00
|
||||
kp_released: usage_page 0x07 keycode 0x09 implicit_mods 0x00 explicit_mods 0x00
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 {
|
||||
slash_macro: slash_macro {
|
||||
#binding-cells = <2>;
|
||||
label = "ZM_SLASH";
|
||||
compatible = "zmk,behavior-macro-two-param";
|
||||
wait-ms = <40>;
|
||||
tap-ms = <40>;
|
||||
bindings = <
|
||||
¯o_param_1to1 &kp MACRO_PLACEHOLDER
|
||||
&kp SLASH
|
||||
¯o_param_2to1 &kp MACRO_PLACEHOLDER>;
|
||||
};
|
||||
|
||||
to_second_macro: to_second_macro {
|
||||
#binding-cells = <2>;
|
||||
label = "ZMK_TO_SECOND";
|
||||
compatible = "zmk,behavior-macro-two-param";
|
||||
wait-ms = <40>;
|
||||
tap-ms = <40>;
|
||||
bindings = <
|
||||
¯o_param_1to2 &mt LSHIFT MACRO_PLACEHOLDER
|
||||
¯o_param_2to2 &mt RSHIFT MACRO_PLACEHOLDER>;
|
||||
};
|
||||
|
||||
quote_letter_macro: quote_letter_macro {
|
||||
#binding-cells = <1>;
|
||||
label = "ZMK_QLET";
|
||||
compatible = "zmk,behavior-macro-one-param";
|
||||
wait-ms = <40>;
|
||||
tap-ms = <40>;
|
||||
bindings = <
|
||||
&kp QUOT
|
||||
¯o_param_1to1 &kp MACRO_PLACEHOLDER
|
||||
&kp QUOT>;
|
||||
};
|
||||
};
|
||||
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label = "Default keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&slash_macro A B "e_letter_macro B
|
||||
&to_second_macro E F &kp C>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&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,10) ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,1000)>;
|
||||
};
|
||||
Reference in New Issue
Block a user