Reg downtime

Please help me in solving the problem below.

How to find out the system downtime means calculating the time during which the user saves the system in standby mode (i.e. without moving the mouse and without touching the keyboard), and between which the system downtime. I also need Excel or mail to send to the user with a summary of all the downtime for this day and for this particular system.

Regards, Chandu.

+4
source share
1 answer

You can find out where the user mouse uses PointerInfo :

MouseInfo.getPointerInfo().getLocation() 

Continue to poll the location of the pointer using this method, and if you find that the location has changed since the last check, reset the downtime to 0. Here are a few test codes:

 public static void main(String[] args) throws Exception { long idleTime = 0 ; long start = System.currentTimeMillis(); Point currLocation = MouseInfo.getPointerInfo().getLocation(); while(true){ Thread.sleep(1000); Point newLocation = MouseInfo.getPointerInfo().getLocation(); if(newLocation.equals(currLocation)){ //not moved idleTime = System.currentTimeMillis() - start; } else{ System.out.printf("Idle time was: %s ms", idleTime); idleTime=0; start = System.currentTimeMillis(); break; } currLocation = newLocation; } } 

Also check out this blog post that identifies downtime with JNA.

+5
source

All Articles