AutoPercenty3/sleep_control.py

19 lines
520 B
Python

import ctypes
import atexit
# Windows API Constants
ES_CONTINUOUS = 0x80000000
ES_SYSTEM_REQUIRED = 0x00000001
ES_DISPLAY_REQUIRED = 0x00000002
def prevent_sleep_mode():
"""슬립 모드 방지"""
ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)
def restore_sleep_mode():
"""슬립 모드 복원"""
ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
# 프로그램 종료 시 슬립 모드 복원
atexit.register(restore_sleep_mode)