I want to detect when the battery power status of a PC (ex.: a laptop) changes. I am using GetSystemPowerStatus API to get battery life percentage. What I want to do is to detect if the battery life percentage changes. The easy way to do this would be using a timer but that would lag my app. I was thinking about a 'recursive' loop.
It would go kind of like this:
and then return the new battery life percentage.Code:Do Until batteryLifePercentageChanges checkIfBatteryLifePercentageChanges Loop
Here is the code to find the battery power percentage:
I am not really good with loops. They can really confuse me sometimes. For example I remember once that when I was working with loops a lot, I asked myself "How does a loop know when to begin?" and stupid stuffs like that. LoLCode:Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As _ SYSTEM_POWER_STATUS) As Long Private Type SYSTEM_POWER_STATUS ACLineStatus As Byte BatteryFlag As Byte BatteryLifePercent As Byte Reserved1 As Byte BatteryLifeTime As Long BatteryFullLifeTime As Long End Type Private Sub Command1_Click() Dim MyStatus As SYSTEM_POWER_STATUS Dim MyLifeTime As Double GetSystemPowerStatus MyStatus MyLifeTime = MyStatus.BatteryLifeTime If MyLifeTime = -1 Then MsgBox "Using AC Power" Else MsgBox "I have " & MyLifeTime / 3600 & " hours remaining on battery." End If End Sub
Any help would be appreciated. Thank you![]()




Reply With Quote
