应用在冻结屏幕像素时冻结

时间:2018-10-18 16:28:36

标签: java loops

我的应用程序在每100毫秒运行一次的计时器中执行此代码时冻结:

Dimension screenRect = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot = null;
try {
    robot = new Robot();
} catch (AWTException e) {
}
for(int y = screenRect.height / 2 - 50; y < screenRect.height / 2 + 50; y++) {
    for(int x = screenRect.width / 2 - 50; x < screenRect.width / 2 + 50; x++) {
        Color c = robot.getPixelColor(x, y);
        if(c.getRed() >= 170 && c.getGreen() >= 90 && c.getBlue() >= 80) {
             robot.keyPress(KeyEvent.VK_A);
             robot.keyRelease(KeyEvent.VK_A);
        }
    }
}

如果在其中找到颜色,则应按A。但是它会冻结,不会循环播放并停止工作。

0 个答案:

没有答案
相关问题