Keep Your Screen On With Python



My Windows desktop computer is set to turn the screen off after one minute of inactivity. It's usually a good idea. Except when I am reading something on screen. Then it is terribly annoying. Most media players can prevent Windows from turning off the screen by calling [SetThreadExecutionState](https://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx). Well. So can I:
import ctypes
ctypes.windll.kernel32.SetThreadExecutionState(0x80000002)
input('screen stays on. press any key to exit.')
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
Pretty neat, huh? Python really can do all things.

Leave a Reply

Your email address will not be published. Required fields are marked *