feat(detect): handle modifiers release event on macOS

This commit is contained in:
Federico Terzi 2021-10-13 22:34:36 +02:00
parent 7987e01d72
commit 379ab08cf1
2 changed files with 12 additions and 0 deletions

View File

@ -25,6 +25,11 @@ pub enum InputEvent {
Mouse(MouseEvent), Mouse(MouseEvent),
Keyboard(KeyboardEvent), Keyboard(KeyboardEvent),
HotKey(HotKeyEvent), 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)] #[derive(Debug, PartialEq)]

View File

@ -241,6 +241,13 @@ impl From<RawInputEvent> for Option<InputEvent> {
INPUT_EVENT_TYPE_KEYBOARD => { INPUT_EVENT_TYPE_KEYBOARD => {
let (key, variant) = key_code_to_key(raw.key_code); 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 value = if raw.buffer_len > 0 {
let raw_string_result = let raw_string_result =
CStr::from_bytes_with_nul(&raw.buffer[..((raw.buffer_len + 1) as usize)]); CStr::from_bytes_with_nul(&raw.buffer[..((raw.buffer_len + 1) as usize)]);