-
-
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 :/
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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)