Created
July 30, 2020 07:38
-
-
Save lukifer195/b6e8aba108ef2752568c4237ae40052b to your computer and use it in GitHub Desktop.
Turn monitor off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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