From 585e062e87dbb227e73e2cb31d5041ff5520fb4d Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 18 May 2020 23:34:36 -0400 Subject: Initial basic modifiers support. --- src/hid.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/hid.c') diff --git a/src/hid.c b/src/hid.c index faf3cfc..234c624 100644 --- a/src/hid.c +++ b/src/hid.c @@ -4,6 +4,22 @@ static struct zmk_hid_report report = { .modifiers = 0, .keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; +#define _TOGGLE_MOD(mod, state) \ + if (modifier > MOD_RGUI) \ + { \ + return -EINVAL; \ + } \ + WRITE_BIT(report.modifiers, mod, state); + +int zmk_hid_register_mod(zmk_mod modifier) +{ + _TOGGLE_MOD(modifier, true); +} +int zmk_hid_unregister_mod(zmk_mod modifier) +{ + _TOGGLE_MOD(modifier, false); +} + #define KEY_OFFSET 0x02 #define MAX_KEYS 6 @@ -24,6 +40,11 @@ static struct zmk_hid_report report = { int zmk_hid_press_key(zmk_key code) { + if (code >= KC_LCTL && code <= KC_RGUI) + { + return zmk_hid_register_mod(code - KC_LCTL); + } + if (code > ZMK_HID_MAX_KEYCODE) { return -EINVAL; @@ -38,6 +59,11 @@ int zmk_hid_press_key(zmk_key code) int zmk_hid_release_key(zmk_key code) { + if (code >= KC_LCTL && code <= KC_RGUI) + { + return zmk_hid_unregister_mod(code - KC_LCTL); + } + if (code > ZMK_HID_MAX_KEYCODE) { return -EINVAL; -- cgit v1.2.3