I finally got tired of typing a long password with special characters several time a day.
I put this script together so I can lock/unlock my computer, yet not have to input a password. (Actually I incorporated all of this script into my main script.)
This script does the following:
1. Sets #m hotkey to turn the monitor(s) on or off
2. Creates a timer so that your computer doesn't go into save screen mode while the monitor is off. See setting where 'checkidle' is.
3. Provides protection in case somebody presses ctrl-alt-del (otherwise you would have to do a hard reboot)
4. Provides protection in case somebody presses win-l (otherwise you would have to do a hard reboot)
5. Explains how to not accidentally exit the script with the monitor still off, see #x
So now all one has to do to secure their computer is press win-m and then press win-m again to use the computer again.
Some limits:
If somebody types on the keyboard while the monitors are off: Those characters would show up in whatever data field a cursor was in when you turned the monitor off. I considered putting the entire list of keyboard keys into the "#if (LockScreen = "on")" section as a::, b::..., but if somebody is really trying to hack your computer while the monitor is off, you probably have bigger problems.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; SetTimers should be in the 'autoexecute' section of your script
SetTimer, LockScreen, 250 ; This timer will keep the screen off when Lockscreen is set to "on"
SetTimer, CheckIdle, 90000 ; Set this timer to 90 seconds (can be adjusted to taste)
return ; autoexecute section ends here
LockScreen: ; here is where the screen is turned off
{
If (LockScreen = "on")
{
SendMessage, 0x112, 0xF170, 2,, Program Manager
}
return
}
CheckIdle: ; here is where your auto screen saver is overridden
{
If (A_TimeIdle > 1680000) ; set the number here to the time it takes for your screensaver to turn on minus 2 minutes (can be adjusted to taste).
; This number is in milliseconds.
{
Send {RShift} ; the most innocuous key I could think of.
}
return
}
#m:: ; the hotkey that sets 'LockScreen' to on or off.
{
If (LockScreen = "on")
{
LockScreen := "off"
sleep, 10
SendMessage, 0x112, 0xF170, -1,, Program Manager
}
else
{
LockScreen := "on"
}
return
}
#l:: ; In case someone used win-l to try to log into the system. This will take the user to the lock screen
; this is because win-l is caught by windows (although it can be "turned off" in the registry).
; You would then type in your regular password.
{
LockScreen := "off"
sleep, 10
SendMessage, 0x112, 0xF170, -1,, Program Manager
return
}
#if (LockScreen = "on") ; this is used so ctrl-alt-del will only go to the lockscreen when LockScreen = "on" (screen is off)
^!Del:: ; In case someone uses ctrl-alt-del to try to log into the system. This will take the user to the lock screen
; this is because ctrl-alt-del is hard coded into the system and can't be overridden by AHK.
; You would then type in your regular password.
{
LockScreen := "off"
sleep, 10
SendMessage, 0x112, 0xF170, -1,, Program Manager
DllCall("LockWorkStation")
return
}
#if
#x:: ; Your ExitApp hotkey should have the following in the script in case it is accidentally pressed while screen is off.
{
LockScreen := "off"
sleep, 10
SendMessage, 0x112, 0xF170, -1,, Program Manager
ExitApp
}