0

I have a keyboard which has a left Windows Key and a right context menu key. I would prefer the right context menu key to work as another Windows Key, so I am using a simple AutoHotKey script to "remap" the key as follows:

AppsKey::LWin

This works great for every WinKey + (XYZ) combination such as Win+I, Win+X, and a bunch of other hotkeys that I have mapped with AutoHotKey.

HOWEVER! it does not work with Win+L to lock the console, which is one of the main reasons I want to remap that key. Anyone have any ideas why?


(Note: if this helps anyone, I have instead used the Scroll Lock key as a "lock console" key instead with this script:

scrolllock:: DllCall("LockWorkStation") 

but I would still like to know why the Win+L functionality is not working)

sǝɯɐſ
  • 2,470
  • 4
  • 33
  • 47

4 Answers4

1

I have found that Windows Key L is treated as an extra special thing. I don't think it shows up in the AutoHotkey keyboard history tool. I vaguely remember using it in the past for something else and when maybe Windows 7 came out, it became impossible. Basically, I think it's a security feature.

Programmer Paul
  • 488
  • 1
  • 3
  • 13
1

In my case, the only reason I want to remap the Menu key (AppsKey) is to be able to lock my screen (since that button is close to the 'L' key and the only Windows key on my natural-style keyboard is far away).

If you don't care about the Menu key working as a Windows key for anything else, you can use this mapping:

AppsKey & L:: DllCall("LockWorkStation")

Of course, you should be able to add other key combinations that are important to you as well. It just seems that you must be explicit for this key.

Brian
  • 11
  • 1
  • right, that's exactly the reason why I wanted to remap the key... good call that you could remap the combination, but I still wonder why it doesn't work by default when the AppsKey is remapped to the Windows key. – sǝɯɐſ Oct 16 '13 at 19:51
1

Update: This seems to get easily confused about the state of the keys. My computer just locked by only typing the L key. So I don't recommend it.

Putting ~ in front of the lock hotkey expression seems to allow AppsKey to act as LWin and also lock the computer.

AppsKey:: LWin
~AppsKey & l:: DllCall("LockWorkStation")

I'm not sure I understand this explanation from the docs, but it seems to apply to this.

If the tilde prefix is applied to a custom modifier key (prefix key) which is also used as its own hotkey, that hotkey will fire when the key is pressed instead of being delayed until the key is released. For example, the ~RButton hotkey above is fired as soon as the button is pressed. Prior to [v1.1.14] (or without the tilde prefix), it was fired when the button was released, but only if the RButton & C combination was not activated.

If the tilde prefix is applied only to the custom combination and not the non-combination hotkey, the key's native function will still be blocked.

Community
  • 1
  • 1
Adam Jones
  • 13
  • 3
  • Perfect! This is what I was looking for. ...although just as I was typing this I got into the state you describe where just typing 'L' locks the computer. I can't reproduce the issue again. – Matthew Nov 14 '19 at 19:47
1

The following autohotkey script worked for me. The script remaps my lock (WIN+L) key to backspace (because it is near backspace and I kept hitting it by accident). I've made CTRL-WIN-L my new lock hotkey.

Note: This code disables workstation locking including via the start menu and ctrl-alt-delete menu. The only way to lock is using CTRL-WIN-L.

1.  Install autohotkey
2.  Put save this scrip with a .ahk extension on your PC.
3.  Right click and compile
4.  Use windows scheduler to start the compiled .exe when you login or at 
    start up and be sure to select "Run with highest privileges" otherwise 
    to registry writes will fail and it won't work.   Otherwise find some 
    other code to manage registry access or run as admin manually.
#InstallKeybdHook
/*
** THanks to this post for the basis of this script! "https://www.autohotkey.com/board/topic/58260-is-there-really-no-way-to-disableremap-winl/"
*/

; Disable win + l key locking (This line must come before any hotkey assignments in the .ahk file)

RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1

;WIN+L
#l up::
send {Backspace down}
send {Backspace up}
exit

;CTRL+WIN+L
^#l::
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0
DllCall("LockWorkStation")
;after locking workstation force a reload of this script which effectively disables Win + L locking the computer again
Reload