1

I'm using low level hooks, but I can't determine what key was pressed. Values are the same for every single key. Is here something I'm doing wrong?

Hook method

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);
}

Callback definition (I do have content in the app)

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

Values given with any key pressed

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

just the wParam changes to 0x101 on key up (0x100 on key down)

Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99
  • If I may ask, what is the overall scenario? There might be other ways to achieve what you're trying to do. Also are any of the API calls that you're making failing? Did you check the return value of SetWindowsHookEx? – obelix Aug 16 '10 at 16:51
  • 1
    did you even try to look it up in MSDN? lParam is more than just a number. also I agree with obelix that there's probably a better way to accomplish your overall goal than keyboard hooking. – tenfour Aug 16 '10 at 16:51
  • @tenfour Thanks, that was indeed helpful. Would you mind posting it as an answer with `KBDLLHOOKSTRUCT *kbdStruct = (KBDLLHOOKSTRUCT*)lParam;`. Thanks – Mikulas Dite Aug 16 '10 at 17:02

1 Answers1

3

KBDLLHOOKSTRUCT *kbdStruct = (KBDLLHOOKSTRUCT*)lParam;

:)

tenfour
  • 36,141
  • 15
  • 83
  • 142