1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <windows.h>
#include <tchar.h>
HHOOK hHook;
__declspec(dllexport) LRESULT CALLBACK KeyHookProc(int code, WPARAM wParam, LPARAM lParam)
{
//Return things we shouldn't handle
if(code < 0)
CallNextHookEx(hHook, code, wParam, lParam);
return CallNextHookEx(hHook, code, wParam,lParam);
}
__declspec(dllexport) BOOL CALLBACK KeyHookSetup(HINSTANCE hDLL, HOOKPROC procPtr)
{
hHook = SetWindowsHookEx(WH_KEYBOARD, procPtr, hDLL, 0);
if(hHook == NULL)
{
MessageBox(NULL, _T("Could not start hook"), _T("Error"), MB_OK | MB_ICONERROR);
return FALSE;
}
return TRUE;
}
__declspec(dllexport) BOOL CALLBACK KeyHookFree(void)
{
if(UnhookWindowsHookEx(hHook) != 0)
{
MessageBox(NULL, _T("Could not free hook"), _T("Error"), MB_OK | MB_ICONERROR);
}
return TRUE;
}
|