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.
You can always use the Windows+L shortcut to lock your session, but your screen will still be open for some time — not very good for privacy or battery life. If you're looking for an alternative without the downside, this script is for you. It uses Windows power management to shut down the screen, and it does it 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 Lock PC script can come in handy during your work day, but at the end of the day you might want to log off instead of just locking your session. Here is how you can do this:
002: SendMessage,0x112,0xF170,2,,Program Manager Sleep, 2000 Shutdown, 0 Return
In this script, we do not use a DLL. The "Shutdown, 0" instruction makes an automatic reference to a DLL to log you out of your session. In this case, when you want to log off, you have to turn off the screen first and then log off. If you reverse the commands, your session will log off (including AutoHotkey) before executing the second part of the script, and your screen will stay on.