Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-assign/override hotkey (Win + L) to lock windows

Tags:

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.

like image 962
Mohit Avatar asked Nov 19 '08 05:11

Mohit


People also ask

How do I set my Windows L to lock?

Press the Windows Key + L Press the Windows and L keys at the same time. It should lock instantly.

How do I lock Windows without Ctrl Alt Delete?

Windows-L Hit the Windows key and the L key on your keyboard. Keyboard shortcut for the lock!


2 Answers

You need to set the following registry key to completely disable the Windows locking feature:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001 

And restart the computer.

This works on Win7, Win8 and Win10

like image 104
franc0is Avatar answered Sep 19 '22 23:09

franc0is


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.

like image 28
efotinis Avatar answered Sep 20 '22 23:09

efotinis