Quickly lock your PC and turn off the screen


/ Published in: AutoIt
Save to your folder(s)

This is a AutoHotKey.com script. It runs on Windows and allows you to lock your computer by simply hitting a single key combination and unlock it with a different one. Download the whole script at the url listed.


Copy this code and paste it in your HTML
  1. ; Program: LockScreen utility
  2. ; Author: Dean Householder
  3. ; Website: http://www.deanhouseholder.com/
  4. ; Version: 1.3 9/28/2012
  5. ; Copyright: GPL
  6.  
  7. #SingleInstance, Force
  8. #Persistent
  9.  
  10. IniPath = %A_WorkingDir%\LockScreen.ini
  11.  
  12. If !A_IsCompiled
  13. Menu, Tray, Icon, %A_ScriptDir%\LockScreen.ico
  14. Menu, Tray, Icon, %A_ScriptName%
  15.  
  16. IfNotExist, %IniPath%
  17. {
  18. FileAppend, , %IniPath%, CP0
  19. IniWrite, ^6, %IniPath%, LockScreen, LockHotkeyStart
  20. IniWrite, F10, %IniPath%, LockScreen, LockHotkeyEnd
  21. IniWrite, true, %IniPath%, LockScreen, TurnOffScreen
  22. IniWrite, true, %IniPath%, LockScreen, RunScreenSaver
  23. IniWrite, 1, %IniPath%, LockScreen, UnlockDuration
  24. }
  25.  
  26. IniRead, LockHotkeyStart, %IniPath%, LockScreen, LockHotkeyStart
  27. IniRead, LockHotkeyEnd, %IniPath%, LockScreen, LockHotkeyEnd
  28. IniRead, LockHotkeyEnd, %IniPath%, LockScreen, LockHotkeyEnd
  29. IniRead, TurnOffScreen, %IniPath%, LockScreen, TurnOffScreen
  30. IniRead, RunScreenSaver, %IniPath%, LockScreen, RunScreenSaver
  31. IniRead, UnlockDuration, %IniPath%, LockScreen, UnlockDuration
  32.  
  33. Hotkey, %LockHotkeyStart%, StartLock, UseErrorLevel
  34. Hotkey, %LockHotkeyEnd%, EndLock, UseErrorLevel
  35.  
  36. ~ESC::
  37. Reload
  38.  
  39.  
  40. StartLock:
  41. IfWinNotExist, BlackScreen1 ahk_class AutoHotkeyGUI
  42. {
  43. SetFormat Integer, Dec
  44. SysGet, Monitors, MonitorCount ; Count monitors
  45. Loop, %Monitors% ; Loop through each monitor
  46. {
  47. SysGet, Mon%A_Index%, Monitor, %A_Index% ; Get this monitor's stats
  48. Width := Mon%A_Index%Right - Mon%A_Index%Left
  49. Height := Mon%A_Index%Bottom - Mon%A_Index%Top
  50. ;MsgBox, % "Left: " Mon%A_Index%Left " | Top: " Mon%A_Index%Top " | Right: " Mon%A_Index%Right " | Bottom: " Mon%A_Index%Bottom "`n" Width "x" Height
  51.  
  52. ; Create a large black window to cover all other windows for each monitor
  53. Gui %A_Index%: -Caption +ToolWindow +AlwaysOnTop
  54. Gui %A_Index%: Color, Black
  55. Gui %A_Index%: Font, s36 c555555
  56. Gui %A_Index%: Add, Text, % "x" Width//2-85 " y" Height//2-80, Locked
  57. Gui %A_Index%: Show, % "x" Mon%A_Index%Left " y" Mon%A_Index%Top " w" Width " h" Height Hide, BlackScreen%A_Index%
  58. Gui %A_Index%: Show
  59. }
  60. IfEqual, RunScreenSaver, true
  61. {
  62. RegRead, ScreenSaver, HKCU, Control Panel\Desktop, SCRNSAVE.EXE
  63. If (ScreenSaver != "")
  64. {
  65. Run, %ScreenSaver% /s ; Start the Screen Saver
  66. ;SendMessage, 0x112, 0xF140, 0,, Program Manager ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE
  67. }
  68. }
  69. IfEqual, TurnOffScreen, true
  70. {
  71. SetFormat Integer, Hex
  72. Loop 255 ; Loop through every character
  73. {
  74. Hotkey % "*vk" SubStr(A_Index+256,4), TurnOffScreen ; Set a hotkey for each character to turn off screen--very annoying
  75. }
  76. }
  77. WinActivate, BlackScreen1 ; Try to cover up the start bar
  78. }
  79.  
  80. EndLock:
  81. IfWinExist BlackScreen1 ahk_class AutoHotkeyGUI
  82. {
  83. KeyWait, %LockHotkeyEnd%, T%UnlockDuration% ; Expect the end Lockkey to be pressed for one second
  84. If ErrorLevel
  85. {
  86. SetFormat Integer, Dec
  87. SysGet, Monitors, MonitorCount ; Count monitors again in case it changed while locked
  88. Loop, %Monitors%
  89. {
  90. Gui %A_Index%: Destroy ; Kill previous black screen GUI's
  91. }
  92. SetFormat Integer, Hex
  93. Loop 255 ; Loop through every character
  94. {
  95. Hotkey % "*vk" SubStr(A_Index+256,4), Off
  96. }
  97. Send, {Shift} ; Press a key to wake up the screensaver
  98. Reload
  99. }
  100. }
  101.  
  102. TurnOffScreen:
  103. SendMessage, 0x112, 0xF170, 2,, Program Manager ; Turn off the monitor(s)

URL: http://www.deanhouseholder.com/projects/lockscreen/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.