Skip to content

Instantly share code, notes, and snippets.

@x011
Last active July 15, 2022 09:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x011/dc1fcdd11fb2ac157865e1e7cf2caeba to your computer and use it in GitHub Desktop.
Save x011/dc1fcdd11fb2ac157865e1e7cf2caeba to your computer and use it in GitHub Desktop.
Pyhon script to turn the monitor On/Off on windows systems.
import win32gui, win32con
from time import sleep
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) # Off
sleep(2)
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) # On
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment