title: nim調用GetSystemPowerStatus判斷筆記本電腦是否接通外接電源
tags:nim,winapi,dll
---git
轉載條件:若是你須要轉載本文,你須要作到完整轉載本文全部的內容,不得刪改文內的做者名字與連接。不然拒絕轉載。github
nim調用GetSystemPowerStatus判斷筆記本電腦是否接通外接電源:api
type SYSTEM_POWER_STATUS* {.final, pure.} = object ACLineStatus*: int8 BatteryFlag*: int8 BatteryLifePercent*: int8 Reserved1*: int8 BatteryLifeTime*: int32 BatteryFullLifeTime*: int32 var test:SYSTEM_POWER_STATUS proc getPowerStatus*(stat:var SYSTEM_POWER_STATUS):int {.stdcall, dynlib:"kernel32", importc:"GetSystemPowerStatus", discardable.} test.getPowerStatus echo test echo "電池電量:",test.BatteryLifePercent if test.ACLineStatus == 0: echo "筆記本,斷電了" elif test.ACLineStatus == 1: echo "筆記本,接通外接電源中" else: echo "我以爲我多是運行在一臺臺式電腦上了。"
代碼抄自:
https://github.com/nim-lang/oldwinapicode
codegay
2017年12月01日 20時26分02秒get