重置 windows 空闲时间
Resetting windows idle time
我写了一个小程序,即使在电池设置无法更改的情况下,它也能让我的电脑保持唤醒状态:https://github.com/xlaech/Anti-Lock-5000。我当前的设置使用点击来重置空闲计时器。
我在问自己:既然有一个结构可以节省空闲时间(https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-lastinputinfo),有没有办法覆盖这个值,让计算机在没有任何用户可见的情况下进入睡眠状态?
虽然 python 中的解决方案不是必需的 - 它需要是一个可移植的解决方案(例如,没有库,没有下载)。
使用SetThreadExecutionState
(as mentioned by @IInspectable):
import time
from ctypes import windll
ES_CONTINUOUS = 0x80000000 # Causes the set state to remain
ES_DISPLAY_REQUIRED = 0x00000002 # Forces the display to be on
flags = ES_CONTINUOUS | ES_DISPLAY_REQUIRED
windll.kernel32.SetThreadExecutionState(flags)
while True:
time.sleep(36000) # Keep process alive, but sleep to prevent system load
我写了一个小程序,即使在电池设置无法更改的情况下,它也能让我的电脑保持唤醒状态:https://github.com/xlaech/Anti-Lock-5000。我当前的设置使用点击来重置空闲计时器。
我在问自己:既然有一个结构可以节省空闲时间(https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-lastinputinfo),有没有办法覆盖这个值,让计算机在没有任何用户可见的情况下进入睡眠状态?
虽然 python 中的解决方案不是必需的 - 它需要是一个可移植的解决方案(例如,没有库,没有下载)。
使用SetThreadExecutionState
(as mentioned by @IInspectable):
import time
from ctypes import windll
ES_CONTINUOUS = 0x80000000 # Causes the set state to remain
ES_DISPLAY_REQUIRED = 0x00000002 # Forces the display to be on
flags = ES_CONTINUOUS | ES_DISPLAY_REQUIRED
windll.kernel32.SetThreadExecutionState(flags)
while True:
time.sleep(36000) # Keep process alive, but sleep to prevent system load