开发者

Reg calculating system idle time

Please help me on the below problem

How to find out the System idle time, means to calcuclate the time the user keeps the system idle (ie without moving the mouse and without touching the keyboard) and between which time the system is idle .Also i should require an excel or mail to be send to the user with the summation of all the idle times for that day & for that particular system.

Regards, Chand开发者_开发技巧u.


You can find out where the user's mouse is using PointerInfo:

MouseInfo.getPointerInfo().getLocation()

Keep polling the pointer location use this method and if you find that the location has changed since the last time you checked, reset the idle time back to 0. Here is some test code:

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 take a look at this blog post, which detects idle time using JNA.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜