Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when the laptop is running on batteries?

Tags:

delphi

How to detect (from Delphi) when the laptop is running on batteries (or AC)?

like image 271
Server Overflow Avatar asked Oct 28 '09 19:10

Server Overflow


People also ask

How do I check the battery cycle on my Dell laptop?

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).

Does laptop still use battery when plugged in?

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.


1 Answers

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;
like image 176
Reallyethical Avatar answered Nov 04 '22 02:11

Reallyethical