Mouse-related behaviours
This commit is contained in:
parent
e585af2aa1
commit
aefbd5edc9
12 changed files with 229 additions and 2 deletions
|
@ -55,6 +55,9 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
|
|||
target_sources(app PRIVATE src/behaviors/behavior_transparent.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_none.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_mouse_key_press.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_mouse_move.c)
|
||||
target_sources(app PRIVATE src/behaviors/behavior_mouse_wheel.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
|
||||
target_sources(app PRIVATE src/combo.c)
|
||||
target_sources(app PRIVATE src/keymap.c)
|
||||
|
|
|
@ -14,3 +14,6 @@
|
|||
#include <behaviors/bluetooth.dtsi>
|
||||
#include <behaviors/ext_power.dtsi>
|
||||
#include <behaviors/outputs.dtsi>
|
||||
#include <behaviors/mouse_key_press.dtsi>
|
||||
#include <behaviors/mouse_move.dtsi>
|
||||
#include <behaviors/mouse_wheel.dtsi>
|
||||
|
|
9
app/dts/behaviors/mouse_key_press.dtsi
Normal file
9
app/dts/behaviors/mouse_key_press.dtsi
Normal file
|
@ -0,0 +1,9 @@
|
|||
/ {
|
||||
behaviors {
|
||||
/omit-if-no-ref/ mkp: behavior_mouse_key_press {
|
||||
compatible = "zmk,behavior-mouse-key-press";
|
||||
label = "MOUSE_KEY_PRESS";
|
||||
#binding-cells = <1>;
|
||||
};
|
||||
};
|
||||
};
|
9
app/dts/behaviors/mouse_move.dtsi
Normal file
9
app/dts/behaviors/mouse_move.dtsi
Normal file
|
@ -0,0 +1,9 @@
|
|||
/ {
|
||||
behaviors {
|
||||
/omit-if-no-ref/ mmv: behavior_mouse_move {
|
||||
compatible = "zmk,behavior-mouse-move";
|
||||
label = "MOUSE_MOVE";
|
||||
#binding-cells = <1>;
|
||||
};
|
||||
};
|
||||
};
|
9
app/dts/behaviors/mouse_wheel.dtsi
Normal file
9
app/dts/behaviors/mouse_wheel.dtsi
Normal file
|
@ -0,0 +1,9 @@
|
|||
/ {
|
||||
behaviors {
|
||||
/omit-if-no-ref/ mwh: behavior_mouse_wheel {
|
||||
compatible = "zmk,behavior-mouse-wheel";
|
||||
label = "MOUSE_WHEEL";
|
||||
#binding-cells = <1>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
description: Mouse key press/release behavior
|
||||
|
||||
compatible: "zmk,behavior-mouse-key-press"
|
||||
|
||||
include: one_param.yaml
|
5
app/dts/bindings/behaviors/zmk,behavior-mouse-move.yaml
Normal file
5
app/dts/bindings/behaviors/zmk,behavior-mouse-move.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Mouse move
|
||||
|
||||
compatible: "zmk,behavior-mouse-move"
|
||||
|
||||
include: one_param.yaml
|
5
app/dts/bindings/behaviors/zmk,behavior-mouse-wheel.yaml
Normal file
5
app/dts/bindings/behaviors/zmk,behavior-mouse-wheel.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Mouse wheel
|
||||
|
||||
compatible: "zmk,behavior-mouse-wheel"
|
||||
|
||||
include: one_param.yaml
|
|
@ -5,5 +5,40 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <dt-bindings/zmk/hid_usage.h>
|
||||
#include <dt-bindings/zmk/hid_usage_pages.h>
|
||||
/* Left click */
|
||||
#define MB1 (0x01)
|
||||
#define LCLK (MB1)
|
||||
|
||||
/* Right click */
|
||||
#define MB2 (0x02)
|
||||
#define RCLK (MB2)
|
||||
|
||||
/* Middle click */
|
||||
#define MB3 (0x04)
|
||||
#define MCLK (MB3)
|
||||
|
||||
#define MB4 (0x08)
|
||||
|
||||
#define MB5 (0x10)
|
||||
|
||||
#define MB6 (0x20)
|
||||
|
||||
#define MB7 (0x40)
|
||||
|
||||
#define MB8 (0x80)
|
||||
|
||||
#define MOVE_UP (0x0000FFFF)
|
||||
|
||||
#define MOVE_DOWN (0x00000001)
|
||||
|
||||
#define MOVE_LEFT (0xFFFF0000)
|
||||
|
||||
#define MOVE_RIGHT (0x00010000)
|
||||
|
||||
#define WHEEL_UP (0x0001)
|
||||
|
||||
#define WHEEL_DOWN (0x00FF)
|
||||
|
||||
#define WHEEL_LEFT (0xFF00)
|
||||
|
||||
#define WHEEL_RIGHT (0x0100)
|
||||
|
|
45
app/src/behaviors/behavior_mouse_key_press.c
Normal file
45
app/src/behaviors/behavior_mouse_key_press.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2021 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zmk_behavior_mouse_key_press
|
||||
|
||||
#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>
|
||||
#include <zmk/hid.h>
|
||||
#include <zmk/endpoints.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
static int behavior_mouse_key_press_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);
|
||||
zmk_hid_mouse_buttons_press(HID_USAGE_ID(binding->param1));
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
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);
|
||||
zmk_hid_mouse_buttons_release(HID_USAGE_ID(binding->param1));
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
|
||||
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
|
||||
|
||||
#define KP_INST(n) \
|
||||
DEVICE_AND_API_INIT(behavior_mouse_key_press_##n, DT_INST_LABEL(n), behavior_mouse_key_press_init, NULL, \
|
||||
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||
&behavior_mouse_key_press_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(KP_INST)
|
49
app/src/behaviors/behavior_mouse_move.c
Normal file
49
app/src/behaviors/behavior_mouse_move.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2021 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zmk_behavior_mouse_move
|
||||
|
||||
#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>
|
||||
#include <zmk/hid.h>
|
||||
#include <zmk/endpoints.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
static int behavior_mouse_move_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);
|
||||
uint32_t x = (binding->param1 & 0xFFFF0000) >> 16;
|
||||
uint32_t y = binding->param1 & 0x0000FFFF;
|
||||
zmk_hid_mouse_movement_press(x, y);
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
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);
|
||||
uint32_t x = (binding->param1 & 0xFFFF0000) >> 16;
|
||||
uint32_t y = binding->param1 & 0x0000FFFF;
|
||||
zmk_hid_mouse_movement_release(x, y);
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
static const struct behavior_driver_api behavior_mouse_move_driver_api = {
|
||||
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
|
||||
|
||||
#define KP_INST(n) \
|
||||
DEVICE_AND_API_INIT(behavior_mouse_move_##n, DT_INST_LABEL(n), behavior_mouse_move_init, NULL, \
|
||||
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||
&behavior_mouse_move_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(KP_INST)
|
50
app/src/behaviors/behavior_mouse_wheel.c
Normal file
50
app/src/behaviors/behavior_mouse_wheel.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2021 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zmk_behavior_mouse_wheel
|
||||
|
||||
#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>
|
||||
#include <zmk/hid.h>
|
||||
#include <zmk/endpoints.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
static int behavior_mouse_wheel_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);
|
||||
int32_t x = (binding->param1 & 0xFF00) >> 8;
|
||||
int32_t y = binding->param1 & 0x00FF;
|
||||
zmk_hid_mouse_wheel_press(x, y);
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
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);
|
||||
int32_t x = (binding->param1 & 0xFF00) >> 8;
|
||||
int32_t y = binding->param1 & 0x00FF;
|
||||
zmk_hid_mouse_wheel_release(x, y);
|
||||
return zmk_endpoints_send_mouse_report();
|
||||
}
|
||||
|
||||
static const struct behavior_driver_api behavior_mouse_wheel_driver_api = {
|
||||
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
|
||||
|
||||
|
||||
#define KP_INST(n) \
|
||||
DEVICE_AND_API_INIT(behavior_mouse_wheel_##n, DT_INST_LABEL(n), behavior_mouse_wheel_init, NULL, \
|
||||
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||
&behavior_mouse_wheel_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(KP_INST)
|
Loading…
Add table
Reference in a new issue