diff --git a/app/SysTray-X/SysTray-X-app/nativeeventfilter-win.cpp b/app/SysTray-X/SysTray-X-app/nativeeventfilter-win.cpp index d1cc593..dac644f 100644 --- a/app/SysTray-X/SysTray-X-app/nativeeventfilter-win.cpp +++ b/app/SysTray-X/SysTray-X-app/nativeeventfilter-win.cpp @@ -4,6 +4,7 @@ /* * System includes */ +#include "windows.h" /* * Qt includes @@ -17,9 +18,19 @@ bool NativeEventFilterWin::nativeEventFilter( const QByteArray& eventType, void* message, long* result ) { Q_UNUSED( eventType ) - Q_UNUSED( message ) Q_UNUSED( result ) + MSG* msg = reinterpret_cast< MSG* >( message ); + + if( msg->message == WM_HOTKEY ) + { + if( msg->wParam == 100 ) + { + activated(); + return true; + } + } + return false; } @@ -41,7 +52,14 @@ bool NativeEventFilterWin::connectShortcut( QKeySequence key_seq ) */ bool NativeEventFilterWin::connectShortcut( Qt::Key key_code, Qt::KeyboardModifiers key_modifiers ) { + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey + + // Set windows callback + RegisterHotKey( (HWND)MainWindow::winId(), // Set the system identifier of the widget window that will handle the HotKey + 100, // Set identifier HotKey + MOD_ALT | MOD_SHIFT, // Set modifiers + 'D' ); // We define hotkeys for HotKey return true; } @@ -53,6 +71,7 @@ bool NativeEventFilterWin::connectShortcut( Qt::Key key_code, Qt::KeyboardModifi bool NativeEventFilterWin::disconnectShortcut() { // Remove windows callback + UnregisterHotKey( (HWND)MainWindow::winId(), 100 ); return true; }