Last active
December 7, 2023 19:12
-
-
Save lboulard/a4c5445e219d146f4191931527233f4c to your computer and use it in GitHub Desktop.
Prevent windows from powering off screen #windows
This file contains hidden or 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
#!/usr/bin/env python3 | |
import ctypes | |
import signal | |
import threading | |
if __name__ == "__main__": | |
SetThreadExecutionState = ctypes.windll.kernel32.SetThreadExecutionState | |
SetThreadExecutionState.argtypes = [ctypes.c_uint32] | |
# https://bugs.python.org/issue35935#msg335056 | |
signal.signal(signal.SIGINT, signal.SIG_DFL) | |
signal.signal(signal.SIGBREAK, signal.SIG_DFL) | |
try: | |
# Replace with 0x80000003 to also reset user idle timer. | |
# Then this prevents device from entering deep power saving or hibernate. | |
state = 0x80000002 | |
SetThreadExecutionState(state) | |
exit = threading.Event() | |
while not exit.is_set(): | |
exit.wait() | |
except KeyboardInterrupt: | |
pass | |
finally: | |
SetThreadExecutionState(state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment