n0tis
n0tis

Reputation: 828

How can I lock my computer with AutoHotkey?

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.

Upvotes: 13

Views: 7743

Answers (3)

Juan
Juan

Reputation: 27

Just improving the code of my fellow camarades, you can block AND turn off the screen if you want to:

#J::
    KeyWait LWin
    KeyWait J
    DllCall("LockWorkStation")
    SendMessage 0x0112, 0xF170, 2,, "Program Manager"
    Return

Upvotes: 1

Thorondale
Thorondale

Reputation: 73

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}

Upvotes: 1

David Metcalfe
David Metcalfe

Reputation: 2412

Per the recommendation in the comments by wOxxOm:

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

Upvotes: 22

Related Questions