#include<iostream>
#include<Windows.h>
using namespace std;
HHOOK kHook = NULL;
LRESULT CALLBACK _keyboard_proc(int ncode, WPARAM wparam, LPARAM lparam)
{
cout << "hit a key" << endl;
return CallNextHookEx(kHook, ncode, wparam, lparam);
}
int main(void)
{
kHook = SetWindowsHookEx(WH_KEYBOARD_LL, reinterpret_cast<HOOKPROC>(_keyboard_proc), GetModuleHandle(NULL), NULL);
if (!kHook)
cout << "set hook fail" << endl;
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}