Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Forces Windows to keep the display on (temporarily disables sleep mode while running). Netflix's silverlight app failed to do this for me :/
import os
import sys
import ctypes
ES_CONTINUOUS = 0x80000000
ES_DISPLAY_REQUIRED = 0x2 #Forces the display to be on by resetting the display idle timer.
ES_SYSTEM_REQUIRED = 0x1 #Forces the system to be in the working state by resetting the system idle timer.
def not_null(result, func, arguments):
if result == 0:
raise WinError()
SetThreadExecutionState = ctypes.windll.kernel32.SetThreadExecutionState
SetThreadExecutionState.restype = int
SetThreadExecutionState.argtypes = (ctypes.c_uint, )
SetThreadExecutionState.errcheck = not_null
def main(argv):
sys.stdout.write("Keeping display on. Press enter to exit.\n")
if __name__ == '__main__':
sys.exit(main(sys.argv) or 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.