• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Detecting power cable unplug?

 
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
 
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.
 
Sheriff
Posts: 22002
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Oh the stink of it! Smell my tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic