我有一个简单的程序来每分钟移动鼠标指针,以避免屏幕保护程序启动。这是在Windows笔记本电脑上运行。 晚上我通常会'冬眠'#39;笔记本电脑和'恢复'在早上。 在恢复时,鼠标移动程序被冻结。 我有两个问题:
该程序的主要部分如下所示 - 这包含在JavaFX应用程序中,其中包含我更新的标签。
go = new Thread() {
@Override
public void run() {
try {
Robot hal = new Robot();
int sec;
PointerInfo pi = null;
while (true) {
sec = 60;
while (sec > 0) {
hal.delay(1000);
pi = MouseInfo.getPointerInfo();
final Point pObj = pi.getLocation();
final int sec2 = sec;
Platform.runLater(() -> lab.setText(String.format("%2d %4d %4d", sec2, pObj.x, pObj.y)));
sec = sec - 1;
}
hal.mouseMove(pi.getLocation().x + 1, pi.getLocation().y + 1);
}
} catch (AWTException ex) {
Logger.getLogger(MouseMoverFX.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
go.start();