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.
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.
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.
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.
Per the recommendation in the comments by wOxxOm:
Esc::
{
DllCall("LockWorkStation")
}
return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With