请帮我解决以下问题
如何找出系统空闲时间,意味着计算用户保持系统空闲的时间(即不移动鼠标而不触摸键盘)以及系统空闲的时间.此外,我应该要求excel或邮件到将该日特定系统的所有空闲时间的总和发送给用户.
此致,Chandu.
您可以找到用户鼠标使用PointerInfo的位置:
MouseInfo.getPointerInfo().getLocation()
Run Code Online (Sandbox Code Playgroud)
使用此方法继续轮询指针位置,如果您发现自上次检查后位置已更改,请将空闲时间重置为0.以下是一些测试代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2749 次 |
最近记录: |