How to detect (from Delphi) when the laptop is running on batteries (or AC)?
Turn on the computer and tap F2 key at the Dell logo screen. On the left pane, under General, select Battery Information. Verify the battery health information as illustrated (Figure 1).
Laptop Batteries Once your battery is charged to full capacity, it will simply stop charging, so keeping your laptop plugged in will not cause any issues to your battery.
To be notified when the status changes on Vista and Windows 7 you can use RegisterPowerSettingNotification
.
For Windows 2000 and later, look at GetSystemPowerStatus
, or go to MSDN and read about Power Management.
(Someone always posts while I am typing :-( )
function GetBattery : Boolean;
var
SysPowerStatus: TSystemPowerStatus;
begin
Win32Check(GetSystemPowerStatus(SysPowerStatus));
case SysPowerStatus.ACLineStatus of
0: Result := False;
1: begin
Result := True;
// You can return life with
// String := Format('Battery power left: %u percent.', SysPowerStatus.BatteryLifePercent]);
end;
else
raise Exception.Create('Unknown battery status');
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With