Okay, I have tried using these functions, but nothing ever goes into my callback function. In my XXX_INIT function, I have:
Code:
...
ActivateKBHook(GetModuleHandle(NULL), LowLevelKeyboardProc);
...
And my callback function looks like:
Code:
/****************************************************************
WH_KEYBOARD_LL hook procedure
****************************************************************/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, L"Callback", L"key", MB_OK);
CHAR szBuf[128];
HDC hdc;
static int c = 0;
size_t * pcch = 0;
HRESULT hResult;
if (nCode < 0) // do not process message
return CallNextHookEx(g_hInstalledLLKBDhook, nCode,
wParam, lParam);
hdc = GetDC(NULL);
hResult = StringCchPrintf(CA2W(szBuf), 128/sizeof(TCHAR), L"KEYBOARD - nCode: %d, vk: %d, %d times ", nCode, wParam, c++);
if (FAILED(hResult))
{
// TODO: write error handler
}
hResult = StringCchLength(CA2W(szBuf), 128/sizeof(TCHAR), pcch);
if (FAILED(hResult))
{
// TODO: write error handler
}
MessageBox(NULL, CA2W(szBuf), L"key", MB_OK);
ReleaseDC(NULL, hdc);
return CallNextHookEx(g_hInstalledLLKBDhook, nCode, wParam,
lParam);
}
That message at the top of the callback never occurs. Sometimes (I don't know what caused it, but it's gone away now), when I pressed a button, it froze the PPC. Well, the PPC would still run in the background, but I couldn't click use the screen at all. I couldn't click anywhere or do anything with it. I had to soft reboot to get it back.
Any ideas on what could be going on? I used the ActivateKBHook and DeactivateKBHook functions from the link that Raul gave me.