When you step away from your work station, you might want to lock your PC to prevent others from using it. At some companies, this is a protocol every employee must follow.
Of course you can use the Windows+L shortcut to lock your session, but your monitor will still be open for some time. If you're trying to save battery life, this script is for you. It uses Windows power management to shut down the monitor, and it does it all with a single keystroke on your Enterpad. To restart your session, just move your mouse or press a key.
Prepare your overlay
Choose an unassigned key on the Enterpad for your lock PC function. Name it something appropriate like “Lock”.
Copy and paste the following script in your AutoHotkey script template (Enterpad.ahk) at the location of the key you wish to assign.
001: DllCall("LockWorkStation") Sleep, 2000 SendMessage,0x112,0xF170,2,,Program Manager Return
The previous script serves you well during your work day, but at the end of it you might want to log off and turn off your screen instead of just locking your computer. Here is how you can do it :
002: SendMessage,0x112,0xF170,2,,Program Manager Sleep, 2000 Shutdown, 0 Return
In this script, we do not use a DLL. Shutdown, 0 makes an automatic reference to a DLL to log off your session. In this case, where you want to log off, you have to turn off the screen first and then log off. If you reverse both commands, your session will log off (including AutoHotkey) and it will not be able to execute the second part of the script, which is to turn off your screen.