I want to implement key strokes (CTRL + KEY
) and therefore used SetWindowsHook (SetWindowsHook(WH_KEYBOARD, hookProcTest)
) to "install" a hook.
Looking at the HOOKPROC
LRESULT CALLBACK hookProcTest(int code, WPARAM wParam, LPARAM lParam)
The code
parameter seems to be always 0, wParam
matches the virtual keycode, lParam
is probably a pointer to a structure containing what key event it is.
When I press a key, realease a key, or press another key, the lParam
shows drastic change.
I tried to cast it to LPCWPRETSTRUCT
but that gave me a trash pointer (program crashed when accessing members).
So what structure is used?
Edit: This was on here: link
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
{
WORD vkCode = LOWORD(wParam); // virtual-key code
BYTE scanCode = LOBYTE(HIWORD(lParam)); // scan code
BOOL scanCodeE0 = (HIWORD(lParam) & KF_EXTENDED) == KF_EXTENDED; // extended-key flag, 1 if scancode has 0xE0 prefix
BOOL upFlag = (HIWORD(lParam) & KF_UP) == KF_UP; // transition-state flag, 1 on keyup
BOOL repeatFlag = (HIWORD(lParam) & KF_REPEAT) == KF_REPEAT; // previous key-state flag, 1 on autorepeat
WORD repeatCount = LOWORD(lParam); // repeat count, > 0 if several keydown messages was combined into one message
BOOL altDownFlag = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN; // ALT key was pressed
BOOL dlgModeFlag = (HIWORD(lParam) & KF_DLGMODE) == KF_DLGMODE; // dialog box is active
BOOL menuModeFlag = (HIWORD(lParam) & KF_MENUMODE) == KF_MENUMODE; // menu is active
// ...
}
break;
The lParam
wasn't a struct - a bunch of bit fields instead - as stated by Remy Lebeau in the comments.