The Win+L is a system assigned hotkey and there's no option to disable it. This means there's no way for an application to detect it, unless you use a low-level global keyboard hook (WH_KEYBOARD_LL
). This works in XP SP3; haven't tested it in Vista though:
LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam) {
KBDLLHOOKSTRUCT& kllhs = *(KBDLLHOOKSTRUCT*)lparam;
if (code == HC_ACTION) {
// Test for an 'L' keypress with either Win key down.
if (wparam == WM_KEYDOWN && kllhs.vkCode == 'L' &&
(GetAsyncKeyState(VK_LWIN) < 0 || GetAsyncKeyState(VK_RWIN) < 0))
{
// Place some code here to do whatever you want.
// ...
// Return non-zero to halt message propagation
// and prevent the Win+L hotkey from getting activated.
return 1;
}
}
return CallNextHookEx(0, code, wparam, lparam);
}
Note that you need a low-level keyboard hook. A normal keyboard hook (WH_KEYBOARD) won't catch hotkey events.