Skip to content

Instantly share code, notes, and snippets.

@lukifer195
Created July 30, 2020 07:38
Show Gist options
  • Save lukifer195/b6e8aba108ef2752568c4237ae40052b to your computer and use it in GitHub Desktop.
Save lukifer195/b6e8aba108ef2752568c4237ae40052b to your computer and use it in GitHub Desktop.
Turn monitor off
import sys
if sys.platform.startswith('linux'):
import os
os.system("xset dpms force off")
elif sys.platform.startswith('win'):
import win32gui
import win32con
from os import getpid, system
from threading import Timer
def force_exit():
pid = getpid()
system('taskkill /pid %s /f' % pid)
t = Timer(0 , force_exit)
t.start()
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2)
t.cancel()
elif sys.platform.startswith('darwin'):
import subprocess
subprocess.call('echo \'tell application "Finder" to sleep\' | osascript', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment