Skip to content

Instantly share code, notes, and snippets.

@joba-1
Forked from EBNull/screenon.py
Created January 10, 2019 18:32
Show Gist options
  • Save joba-1/9420e7cd649ac90dce387b65fceddf17 to your computer and use it in GitHub Desktop.
Save joba-1/9420e7cd649ac90dce387b65fceddf17 to your computer and use it in GitHub Desktop.
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_AWAYMODE_REQUIRED = 0x00000040
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")
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED)
sys.stdin.read(1)
if __name__ == '__main__':
sys.exit(main(sys.argv) or 0)
@joba-1
Copy link
Author

joba-1 commented Sep 11, 2020

FWIW, I use this now: https://github.com/joba-1/Present

It is sourcecode for a self contained exe with only a few kb size. No python, no shell, no install :)

You need platformio though, to build it yourself -> no viruses, no calling home, no trust needed - just look at it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment