Created
May 28, 2023 10:38
-
-
Save puppis42/c9f8ca4bab40ad677e6dfa5df408b6a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Windows.h> | |
void checkBattery() { | |
SYSTEM_POWER_STATUS spsPwr; | |
if (GetSystemPowerStatus(&spsPwr)) { | |
if (spsPwr.ACLineStatus == 0 && spsPwr.BatteryFlag != 128) { // Laptop but not use AC | |
goto jmp; | |
} | |
else if (spsPwr.ACLineStatus == 1 && spsPwr.BatteryFlag != 128) { // Laptop but use AC | |
goto jmp; | |
} | |
else if (spsPwr.ACLineStatus == 255 || spsPwr.BatteryLifePercent > 100) { | |
//some code | |
} | |
//some code | |
//std::cout << "\nAC Status : " << static_cast<double>(spsPwr.ACLineStatus) | |
// << "\nBattery Status : " << static_cast<double>(spsPwr.BatteryFlag) | |
// << "\nBattery Life % : " << static_cast<double>(spsPwr.BatteryLifePercent) | |
// << std::endl; | |
} | |
else { | |
//NOTHING FOUND! | |
//some code | |
} | |
jmp: | |
//std::cout << "11111" << std::endl; | |
while (spsPwr.BatteryLifePercent < 100) { | |
GetSystemPowerStatus(&spsPwr); | |
std::cout << "battery percent is low" << std::endl; | |
Sleep(1000); | |
} | |
} | |
int main() | |
{ | |
checkBattery(); | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment