views:

1688

answers:

3

Is it possible to re-assign the Win + L hotkey to another executable/shortcut?

Use-case - I would like to switch off the monitor of my laptop as soon as it is locked. I know of a executable which can lock and turn off the monitor but I do not want to change the way the system is locked (by running the program explicitly or by some other shortcut). It would be best if Win + L can be assigned to this executable.

+1  A: 

Looks like you can't.

You can disable all built-in Windows hotkeys except Win+L and Win+U by making the following change to the registry (this should work on all OSes but a reboot is probably required):

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer NoWinKeys REG_DWORD 0x00000001 (1)

(http://www.autohotkey.com/docs/misc/Override.htm)

But you could try using Tweak UI. Under the Explorer tree view item, uncheck "Enabled Windows+X" hotkeys. Hoekey also might work, haven't tried it. Source.

amdfan
A: 

Yes, always ask on Win32 api ng :news://194.177.96.26/comp.os.ms-windows.programmer.win32 where it's a classic question for ages... (remember you can do everything with Win32 api)

+4  A: 

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.

efotinis