Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 834
n0tis Avatar asked Feb 18 '17 12:02

n0tis


People also ask

How do I lock my computer with shortcut keys?

Using the Keyboard: Press Ctrl, Alt and Del at the same time. Then, select Lock this computer from the options that appear on the screen.

Does AutoHotkey work when computer is locked?

To put it simply when the PC is in a locked state Windows uses a sort of "alternate desktop" which contains no windows. So, if you have scripts that use commands such as WinWaitActive, WinClose, Send etc., the script will not function correctly because there are no windows that exist in order to be acted upon.

How do I run an AutoHotkey file?

Run a ScriptDouble-click a script file (or shortcut to a script file) in Explorer. Call AutoHotkey.exe on the command line and pass the script's filename as a command-line parameter. After creating the default script, launch AutoHotkey via the shortcut in the Start menu to run it.


1 Answers

Per the recommendation in the comments by wOxxOm:

Esc::
{
DllCall("LockWorkStation")
}
return
like image 74
David Metcalfe Avatar answered Oct 21 '22 04:10

David Metcalfe