1#include "HookWindows.h"
5#include <QLoggingCategory>
7static Q_LOGGING_CATEGORY(log,
"Client.Hook.Windows")
17CHookWindows::CHookWindows(QObject *parent)
24CHookWindows::~CHookWindows()
26 qDebug(log) <<
"CHookWindows::~CHookWindows()";
31LRESULT CALLBACK CHookWindows::keyboardHookProc(INT code, WPARAM wparam, LPARAM lparam)
33 if (code == HC_ACTION)
35 KBDLLHOOKSTRUCT* hook =
reinterpret_cast<KBDLLHOOKSTRUCT*
>(lparam);
41 Qt::KeyboardModifiers keyMdf = Qt::NoModifier;
56 key = Qt::Key_Super_L;
57 keyMdf = Qt::MetaModifier;
62 key = Qt::Key_Super_R;
63 keyMdf = Qt::MetaModifier;
95 CFrmViewer* self = qobject_cast<CFrmViewer*>(QApplication::focusWidget());
96 WId foreground_window =
reinterpret_cast<WId
>(GetForegroundWindow());
97 if (self && self->parentWidget()->window()->winId() == foreground_window)
99 if(wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN)
100 emit self->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, key, keyMdf));
101 if(wparam == WM_KEYUP || wparam == WM_SYSKEYUP)
102 emit self->sigKeyReleaseEvent(
new QKeyEvent(QKeyEvent::KeyRelease, key, Qt::NoModifier));
112 return CallNextHookEx(
nullptr, code, wparam, lparam);
116int CHookWindows::RegisterKeyboard()
119 UnRegisterKeyboard();
120 m_hKeyboard = SetWindowsHookExW(WH_KEYBOARD_LL, keyboardHookProc,
nullptr, 0);
124int CHookWindows::UnRegisterKeyboard()
128 UnhookWindowsHookEx(m_hKeyboard);
129 m_hKeyboard =
nullptr;
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
The class is the HOOK abstract class.