Code:
struct {
unsigned char ACLineStatus; // Checks to see if you're connected to the
// wall outlet or not
unsigned char BatteryFlag; // Battery status
unsigned char BatteryLifePercent; // precentage left
unsigned char Reserved1; // Dont use
long BatteryLifeTime; // Total time left of your battery
long BatteryFullLifeTime; // Total UPtime of your battery
} SYSTEM_POWER_STATUS;
dllimport "kernel32.dll" stdcall long GetSystemPowerStatus(SYSTEM_POWER_STATUS*);
var info = new Object;
info.data = new Struct(SYSTEM_POWER_STATUS);
if (GetSystemPowerStatus(info) != 0) {
if (info.data.ACLineStatus == 1) {
// the battery is online
trace("The battery can still be working for " + info.data.BatteryLifeTime + " seconds");
} else {
trace("The battery isn't online");
}
}
For more details, please see the following MSDN page
SYSTEM_POWER_STATUS Structure (Windows)