Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting power cable unplug?  RSS feed

 
Philippus Scholtz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.

Thanks
 
Philippus Scholtz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

OK, I think I've found the answer. I must use JNA to call the GetPowerStatus function in the kernel32.dll.

Here is an example: Power Status Example
 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like a dotNet example

Power Management in Windows XP that makes use of the Win32 GetSystemPowerStatus function



Drat, too late! looks like you found it while I was formating my post.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!