7
votes

I'm trying to bind "Esc" key to lock my computer with AutoHotkey.

Manually pressing Winkey + l will lock my computer, but it doesn't work in my AutoHotkey script.

esc::
   MsgBox Going to lock
   Send, #l
Return

I have tried multiple other AutoHotkey syntax (without the modifier for example) without success.

2
but I'm not in locked screen screen mode ! I'm in satndard window, and I want to trigger locked scren mode via AHKn0tis
Ah. I see! DllCall("LockWorkStation") instead of send #lwOxxOm

2 Answers

11
votes

Per the recommendation in the comments by wOxxOm:

Esc::
{
DllCall("LockWorkStation")
}
return
0
votes

What you are doing in that code, is pressing the windows key first and then the 'l' key. Not both at the same time. To make key combinations, you need to press the combination key down and then the key you want to combine it with. Remember to release the key afterwards. Your code would then look like:

Send {LWin down}
Send l
Send {LWin up}

or

Send {LWin down}l{LWin up}