I’m playing around with pygame, and one thing I’d like to do is reduce the number of frames per second when the computer is on battery power (to lower the CPU usage and extend battery life).
How can I detect, from Python, whether the computer is currently on battery power?
I’m using Python 3.1 on Windows.
If you want to do it without
win32api, you can use the built-inctypesmodule. I usually run CPython withoutwin32api, so I kinda like these solutions.It’s a tiny bit more work for
GetSystemPowerStatus()because you have to define theSYSTEM_POWER_STATUSstructure, but not bad.On my system that prints this (basically meaning "desktop, plugged in"):