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)){
Also check out this blog post that identifies downtime with JNA.
source share