Files
zmk/docs/docs/keymaps/input-processors/behaviors.md
Pete Johanson cb867f92db Feature: input processor behavior invocation (#2714)
refactor(pointing): Allow stopping event propagation

    Allow input processors to return a special value if a given input event
    should not be further processed/propagated.

feat(pointing): Add behavior input processor

    Add the ability to intercept certain input events and trigger behaviors
    when they occur.

Co-authored-by: Jorge Villalobos <minusfive@users.noreply.github.com>
Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
2024-12-17 20:50:06 -05:00

3.3 KiB

title, sidebar_label
title sidebar_label
Behaviors Input Processor Behaviors

Overview

The behaviors input processor is used invoke standard behaviors when certain input events occur; most frequently this is used to trigger behaviors when certain mouse buttons are triggered by physical pointing devices.

:::note

This input processor is primarily intended for INPUT_EV_KEY type of events that have a binary on/off state, not vector types for relative or absolute movements.

:::

:::note[Source-specific behaviors on split keyboards] Invoking a source-specific behavior such as one of the reset behaviors using this input processor will always trigger it on the central side of the keyboard, regardless of the side includes the input device that originally generated the input event. :::

Usage

When used, this input processor takes no parameters, as the event code to behavior mapping is specified in the definition of the specific processor instance, e.g.:

&zip_button_behaviors

Pre-Defined Instances

One pre-defined instance of the out-of-band behaviors input processor is available:

Reference Description
&zip_button_behaviors Maps left/right/middle clicks to a given behavior.

Should you wish to update the existing instance to trigger different behaviors for each mouse button, you can override the bindings property, e.g.:

&zip_button_behaviors {
    bindings = <&kp A &kp B &kp C>;
};

By default, the bindings property maps all the buttons to &none, so you will want to override the bindings property like above if you use this processor by assigning it to an input listener.

User-Defined Instances

Users can define new instances of the out-of-band behaviors input processor if they want to target different codes or assign different behaviors.

Example

Below example maps the left mouse button code to the middle mouse button.

#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
    input_processors {
        zip_right_click_trigger_paste: zip_right_click_trigger_paste {
            compatible = "zmk,input-processor-behaviors";
            #input-processor-cells = <0>;
            codes    = <INPUT_BTN_1>;
            bindings = <&kp LC(V)  >;
        };
    };
}

Compatible

The behaviors input processor uses a compatible property of "zmk,input-processor-behaviors".

Standard Properties

  • #input-processor-cells - required to be constant value of <0>.

User Properties

  • type - The type of events to scale. Usually, this is INPUT_EV_KEY for key/button events. The default value if omitted is INPUT_EV_KEY.
  • codes - The specific codes of the given type to capture, e.g. button event codes. This list must be the same length as the bindings property.
  • bindings - The bindings to trigger when an event with the corresponding code is processed.