tags:

views:

512

answers:

4

How to detect that a PC has been idle for 30 seconds using Java?

EDITED

With idle I mean that there are no user activity. The user does nothing in 30 seconds. I wold like to do an apllication like Windows, that detects that the user does nothing and enter in stad-by.

+3  A: 

Directly from java it is not possible. You'll have to find some native library and create a JNI wrapper for that.

Dev er dev
+4  A: 

Not possible as requested, but you can create workarounds using the java.lang.management API. A JNI implementation can also be found on javaworld.

soulmerge
+2  A: 

Not easy to do have a look at OperatingSystemMXBean method getSystemLoadAverage() only available since java 6 you could keep a track of it and if it is the same for a while determine the pc is idle.

This assumes idle in terms of idle CPU

OperatingSystemMXBean operatingSystemMxBean = ManagementFactory.getOperatingSystemMXBean();

Paul Whelan
+4  A: 

I've come across this excellent example of detecting system wide idle time using JNA. Java Native Access (JNA) is a library that provides access to Java Native Interface (JNI) without the need for you to actually write native code.

Here the example that is very close to what you're asking for: http://ochafik.free.fr/blog/?p=98

Kevin M.