Skip to content

Instantly share code, notes, and snippets.

@hexiyou
Created October 23, 2019 23:36
Show Gist options
  • Save hexiyou/10e4b259335dbf92fe993c24a8bec654 to your computer and use it in GitHub Desktop.
Save hexiyou/10e4b259335dbf92fe993c24a8bec654 to your computer and use it in GitHub Desktop.
Turn monitor off with a keyboard shortcut with AutoHotKey
; This is part of my AutoHotkey [1] script that turns off my monitor when I
; press Win+\.
; It also turns the screensaver on at the same time, so that Windows Live
; Messenger (and any other programs) know I am away.
; I don't have a password on my screensaver, so there is a second version
; (Win+Shift+\) that locks the PC as well.
; Note: Sometimes the monitor comes back on after a second and I have to
; press it again. Not sure why. Adding "Sleep" to pause first didn't help.
; [1]: http://www.autohotkey.com/
; Win+\
#\::
SendMessage 0x112, 0xF140, 0, , Program Manager ; Start screensaver
SendMessage 0x112, 0xF170, 2, , Program Manager ; Monitor off
Return
; Win+Shift+\
#+\::
Run rundll32.exe user32.dll`,LockWorkStation ; Lock PC
Sleep 1000
SendMessage 0x112, 0xF170, 2, , Program Manager ; Monitor off
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment