什么键被按下了?键盘挂钩

时间:2010-08-16 16:48:47

标签: c++ winapi hook

我正在使用低级挂钩,但我无法确定按下了哪个键。每个键的值都相同。这是我做错了吗?

钩子方法

void hook() {

    /** this part is probably not important since I use global WH_KEYBOARD_LL, is that right? */
    HWND hwnd = FindWindow(NULL, "Vertices.exe");
    HINSTANCE instance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
    /** end part */

    SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, instance /** or NULL ? */, NULL);
}

回调定义(我在应用中有内容)

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);

按下任意键时给出的值

nCode:0 | wParam:0x100 | lParam:0x18fe14

只有wParam在按键向上变为0x101(按键向下为0x100)

1 个答案:

答案 0 :(得分:3)

KBDLLHOOKSTRUCT *kbdStruct = (KBDLLHOOKSTRUCT*)lParam;

:)