下面的Python代码应该打印出自上一次用户活动(鼠标移动、键盘按键按下)后经过的时间
from ctypes import Structure, windll, c_uint, sizeof, byref
import time
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
windll.user32.GetLastInputInfo(byref(lastInputInfo))
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0
for i in range(10):
print get_idle_duration()
time.sleep(1)
问题:但是,如果在脚本执行过程中没有用户输入,则运行此脚本将输出以下结果:
^{pr2}$为什么打印出来的空闲时间没有继续增加,而是看起来像是在不断地重置?在
目前没有回答
相关问题 更多 >
编程相关推荐