Page 1 of 1

ThinkVantage Key and SetWindowsHookEx

Posted: Wed Mar 14, 2007 4:07 pm
by jeffm
I wrote a small c++ program to trap a ThinkVantage key press, but pressing the key does not generate any keyboard input. Has anyone else tried this?

I'm working on a clean-install so I may be missing a driver. Although, I did install the hotkey driver and the keyboard customizer utility.

Here's the hook procedure:

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if( nCode < 0 )
{
return ::CallNextHookEx(g_keyboardHook, nCode, wParam, lParam );
}

KBDLLHOOKSTRUCT* kbd = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
if( kbd->vkCode != THNIKVANTAGE_KEYCODE )
return ::CallNextHookEx(g_keyboardHook, nCode, wParam, lParam );

::ShellExecute(NULL, L"open", L"c:\\windows\\system32\\notepad.exe", NULL, NULL, SW_SHOW);
return STOP_PROCESSING;
}

Posted: Wed Mar 14, 2007 4:31 pm
by Puppy
Global keyboard hooks might be tricky. Have you tried to monitor all keystrokes to be sure you are checking the right virtual-key code ? Also don't forget you need shared data section for the hook handle because the hook DLL is injected into process with foreground window.

Posted: Wed Mar 14, 2007 4:37 pm
by jeffm
Yeah, I set a breakpoint in the handler to verify the hook is installed properly. I can see all key presses except the ThinkVantage button and the volume control buttons.

Thanks for the reminder on the data segment - forgot about that.

Posted: Wed Mar 14, 2007 4:40 pm
by Puppy
One possible scenario is that the Keyboard customizer utility does not call CallNextHookEx in the hook DLL (if there is any). I would rather log into a file because I'm not sure the debuuger can handle this.

Posted: Wed Mar 14, 2007 4:52 pm
by jeffm
I disable the keyboard customizer - no change. Good idea though.

Posted: Wed Mar 14, 2007 5:12 pm
by Puppy
Also I would use WH_KEYBOARD hook instead of WH_KEYBOARD_LL

Posted: Wed Mar 14, 2007 6:16 pm
by sugo
Perhaps ThinkPad HotKey features ate the keystroke?

If WH_KEYBOARD_LL cannot trap it, I highly doubt WH_KEYBOARD can.

Does "Fn" key generate a call to your LowLevelKeyboardProc?

What are you trying to accomplish? If you want to override the action for ThinkVantage key, changing this value is easier:

[HKEY_LOCAL_MACHINE\SOFTWARE\IBM\TPHOTKEY\8001]

Posted: Wed Mar 14, 2007 7:38 pm
by jeffm
Perhaps ThinkPad HotKey features ate the keystroke?
I've tried disabling it...
Does "Fn" key generate a call to your LowLevelKeyboardProc?
Yes...
If you want to override the action for ThinkVantage key, changing this value is easier:

[HKEY_LOCAL_MACHINE\SOFTWARE\IBM\TPHOTKEY\8001]
That was the first thing I tried. Apparently there's some software that must be installed for that to work (and I'm trying to minimize the number of running processes so I'd rather not install it anyway).

Posted: Thu Mar 15, 2007 4:53 am
by jeffm
I tried WH_KEYBOARD - no luck.

Unix has a utility called tpb that enables the thinkpad button for that platform. Looking at the source for tpb, they are reading from /dev/nvram for the button state. Does anyone know if there is an equivalent operation on Windows?

Here's a link to the relevant source file:

http://www.google.com/codesearch?hl=en& ... inkpad.cpp