diff --git a/app/Kconfig b/app/Kconfig index 8f690175..a45f2dc2 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -113,6 +113,12 @@ config ZMK_HID_INDICATORS Enable HID indicators, used for detecting state of Caps/Scroll/Num Lock, Kata, and Compose. +config ZMK_HID_SEPARATE_MOD_RELEASE_REPORT + bool "Release Modifiers Separately" + help + Send a separate release event for the modifiers, to make sure the release + of the modifier doesn't get recognized before the actual key's release event. + menu "Output Types" config ZMK_USB diff --git a/app/src/hid_listener.c b/app/src/hid_listener.c index 2b847082..2d17a395 100644 --- a/app/src/hid_listener.c +++ b/app/src/hid_listener.c @@ -66,6 +66,17 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed return err; } +#if IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + + // send report of normal key release early to fix the issue + // of some programs recognizing the implicit_mod release before the actual key release + err = zmk_endpoints_send_report(ev->usage_page); + if (err < 0) { + LOG_ERR("Failed to send key report for the released keycode (%d)", err); + } + +#endif // IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers); // There is a minor issue with this code. // If LC(A) is pressed, then LS(B), then LC(A) is released, the shift for B will be released @@ -73,7 +84,7 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed // Solving this would require keeping track of which key's implicit modifiers are currently // active and only releasing modifiers at that time. implicit_mods_changed = zmk_hid_implicit_modifiers_release(); - ; + if (ev->usage_page != HID_USAGE_KEY && (explicit_mods_changed > 0 || implicit_mods_changed > 0)) { err = zmk_endpoints_send_report(HID_USAGE_KEY); diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 27923453..cc342195 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -29,10 +29,11 @@ Making changes to any of the settings in this section modifies the HID report de ::: -| Config | Type | Description | Default | -| ------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | -| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| Config | Type | Description | Default | +| -------------------------------------------- | ---- | -------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Release the Modifiers separate from and after the modified key | n | Exactly zero or one of the following options may be set to `y`. The first is used if none are set.