Mega Code Archive

 
Categories / Delphi / Hardware
 

How to get the power status

Title: How to get the power status procedure TForm1.Button1Click(Sender: TObject); var SysPowerStatus: TSystemPowerStatus; begin GetSystemPowerStatus(SysPowerStatus); if Boolean(SysPowerStatus.ACLineStatus) then begin ShowMessage('System running on AC.'); end else begin ShowMessage('System running on battery.'); ShowMessage(Format('Battery power left: %d percent.', [SysPowerStatus.BatteryLifePercent])); end; end;