From a584ee94ec7a7c89355e6b6bafb0492503506620 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 16 Oct 2021 14:42:22 +0200 Subject: [PATCH] fix(detect): filter out values from keyboard events when Alt key is pressed, related to #725 --- espanso-detect/src/win32/native.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/espanso-detect/src/win32/native.cpp b/espanso-detect/src/win32/native.cpp index 3a6f4f5..1ac9d41 100644 --- a/espanso-detect/src/win32/native.cpp +++ b/espanso-detect/src/win32/native.cpp @@ -167,6 +167,15 @@ LRESULT CALLBACK detect_window_procedure(HWND window, unsigned int msg, WPARAM w if (result >= 1) { event.buffer_len = result; + + // Filter out the value if the key was pressed while the ALT key was down + // but not if AltGr is down (which is a shortcut to ALT+CTRL on some keyboards, such + // as the italian one). + // This is needed in conjunction with the fix for: https://github.com/federico-terzi/espanso/issues/725 + if ((lpKeyState[VK_MENU] & 0x80) != 0 && (lpKeyState[VK_CONTROL] & 0x80) == 0) { + memset(event.buffer, 0, sizeof(event.buffer)); + event.buffer_len = 0; + } } else {