3

I have a little program where i need to somehow detect when the user just closes down his/her laptop screen. So; not turning of the entire computer but rather just closing down the screen.

Ive got a chat program and i need to make the user go offline when the screen is closed. For some reason my current socket connection is still alive when i just close down the screen.

Any ideas?

Alosyius
  • 8,771
  • 26
  • 76
  • 120
  • I doubt you can do that in pure Java but if you use jni: http://stackoverflow.com/questions/3355606/detect-laptop-lid-closure-and-opening – assylias Sep 20 '13 at 12:18
  • I use the JNA lib to detect when user is "inactive" maybe that could be used somehow? – Alosyius Sep 20 '13 at 12:21

1 Answers1

2

You can give a look to that library :

http://www.codeproject.com/Articles/6590/PC-StandBy-Detector-for-Java-Apps

It is really simple to use and worked well for me. (Window only)

SegFault
  • 1,094
  • 8
  • 12
  • 1
    It sure doesn't. Such native stuff is obviously platform-specific and a lib should have specific native code for each platform it intends to support. – Marko Topolnik Sep 20 '13 at 12:22
  • Yes, it works only for window since it uses the Win32 API message called WM_POWERBROADCAST. I guess it is going to be hard if you want to find a solution working for any OS. You will probably have to mix different solutions for different OS. – SegFault Sep 20 '13 at 12:24