From 379ab08cf1616de86842efada4cc2bc3d1346dcb Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 13 Oct 2021 22:34:36 +0200 Subject: [PATCH] feat(detect): handle modifiers release event on macOS --- espanso-detect/src/event.rs | 5 +++++ espanso-detect/src/mac/mod.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/espanso-detect/src/event.rs b/espanso-detect/src/event.rs index 6eae8ad..bfd8914 100644 --- a/espanso-detect/src/event.rs +++ b/espanso-detect/src/event.rs @@ -25,6 +25,11 @@ pub enum InputEvent { Mouse(MouseEvent), Keyboard(KeyboardEvent), HotKey(HotKeyEvent), + + // Special event type only used on macOS + // This is sent after a global keyboard shortcut is released + // See https://github.com/federico-terzi/espanso/issues/791 + AllModifiersReleased, } #[derive(Debug, PartialEq)] diff --git a/espanso-detect/src/mac/mod.rs b/espanso-detect/src/mac/mod.rs index d9bc5b0..5b93558 100644 --- a/espanso-detect/src/mac/mod.rs +++ b/espanso-detect/src/mac/mod.rs @@ -241,6 +241,13 @@ impl From for Option { INPUT_EVENT_TYPE_KEYBOARD => { let (key, variant) = key_code_to_key(raw.key_code); + // When a global keyboard shortcut is relased, the callback returns an event with keycode 0 + // and status 0. + // We need to handle it for this reason: https://github.com/federico-terzi/espanso/issues/791 + if raw.key_code == 0 && raw.status == 0 { + return Some(InputEvent::AllModifiersReleased); + } + let value = if raw.buffer_len > 0 { let raw_string_result = CStr::from_bytes_with_nul(&raw.buffer[..((raw.buffer_len + 1) as usize)]);