diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index c7eadcadb6..03bccab47d 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -37,6 +37,46 @@ #include #endif +#if defined(Q_OS_WIN) +#include + +HHOOK hook; +bool isAltPressed = false; +bool isShiftPressed = false; + +// Just an example of global shortcuts on Windows. +// This is hardcoded Alt+Shift+3 shortcut +LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam) { + if (nCode >= 0) { + KBDLLHOOKSTRUCT *kbdStruct = (KBDLLHOOKSTRUCT *)lParam; + if (wParam == WM_SYSKEYDOWN) { + if (kbdStruct->vkCode == VK_LMENU) { + // We're here no matter of order Alt and Shift + isAltPressed = true; + } else if (kbdStruct->vkCode == VK_LSHIFT) { + // We're here if Alt was pressed BEFORE Shift + isShiftPressed = true; + } else if (isAltPressed && isShiftPressed && kbdStruct->vkCode == '3') { + Flameshot::instance()->gui(); + return 1; + } + } else if (wParam == WM_KEYDOWN) { + if (kbdStruct->vkCode == VK_LSHIFT) { + // We're here if Shift was pressed BEFORE Alt + isShiftPressed = true; + } + } else if (wParam == WM_KEYUP) { + if (kbdStruct->vkCode == VK_LMENU) { + isAltPressed = false; + } else if (kbdStruct->vkCode == VK_LSHIFT) { + isShiftPressed = false; + } + } + } + return CallNextHookEx(hook, nCode, wParam, lParam); +} +#endif + Flameshot::Flameshot() : m_captureWindow(nullptr) , m_haveExternalWidget(false) @@ -69,6 +109,9 @@ Flameshot::Flameshot() qApp, [this]() { history(); }); #endif +#if defined(Q_OS_WIN) + hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHook, NULL, 0); +#endif } Flameshot* Flameshot::instance()