Does anybody know if there is a way to detect when a laptop / netbook has been connected / disconnected from AC power? (In Win XP).
I'm working on a little project to use a netbook in my car with a touch screen and I'm powering the netbook from the cigarette lighter via an adapter. I want the program to do certain things when the car's ignition is turned on / off (For example to automatically play music when I turn on the car, etc).
Might be some kind of Windows API call or something. Windows can detect it, because it updates the system tray icon, etc.
posted 9 years ago
OK, I think I've found the answer. I must use JNA to call the GetPowerStatus function in the kernel32.dll.
That function call will work perfectly, but you will need to check with a timer of sorts. ScheduledExecutorService can help you out with that, or java.util.Timer if you have Java 1.4 or before. In user interfaces you can use javax.swing.Timer.