python 调用windows api查看系统的电量
2018-07-20 来源:open-open
通过调用GetSystemPowerStatus Windows Api来判断AC Power是开启还是关闭状态。是一个python调用windows api的例子。
import os
import win32con
import sys
import time
from ctypes import *
class PowerClass(Structure):
_fields_ = [('ACLineStatus', c_byte),
('BatteryFlag', c_byte),
('BatteryLifePercent', c_byte),
('Reserved1',c_byte),
('BatteryLifeTime',c_ulong),
('BatteryFullLifeTime',c_ulong)]
powerclass = PowerClass()
while True:
result = windll.kernel32.GetSystemPowerStatus( byref(powerclass) )
try:
state = int(powerclass.ACLineStatus)
except:
state = 0
if state == 1:
print 'Power is on...'
else:
print 'Power is off...\a' #\a = bell sounds beep on computer
print 'Sleeping for 5 seconds...'
time.sleep(5)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐