Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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: 21842
105
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.
 
Slime does not pay. Always keep your tiny ad dry.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!