LIBS +=User32.LIB
main.cpp: #include "hooktest.h" #include "ui_hooktest.h" #include <QDebug>
LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam);
HHOOK keyHook=NULL; WPARAM lastkey=0; QString lastStr;
int starthook(); HookTest::HookTest(QWidget *parent) : QWidget(parent) , ui(new Ui::HookTest) { ui->setupUi(this); keyHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyProc, GetModuleHandle(NULL), 0);
MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
HookTest::~HookTest() { delete ui; }
LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam){ PKBDLLHOOKSTRUCT key = (PKBDLLHOOKSTRUCT)lParam; qDebug()<<key->vkCode<<endl; return CallNextHookEx(keyHook, nCode, wParam, lParam); }
|