如何找到坐标变化的颜色被识别后需要点击的位置。
程序的目的是完成游戏中的任务,需要点击不同的颜色,这些颜色并不总是在相同的位置。
代码当前在执行程序 5 秒后获取鼠标坐标的颜色
public class RobotColorClick
{
public RobotColorClick () throws AWTException, IOException, InterruptedException
{
Robot robot = new Robot();
//Delay 5 seconds
robot.delay(5000);
//Gets color (value of red,green,blue) from the mouse position after 5 seconds
Color color = robot.getPixelColor( MouseInfo.getPointerInfo().getLocation().x
, MouseInfo.getPointerInfo().getLocation().y);
//Delay 3 seconds
robot.delay(3000);
//Mouse moves to X and Y then right click
//Problem! How to set X and Y to position color coordinates, position will change
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
public static void main(String[] args) throws AWTException, IOException,
InterruptedException
{
new RobotColorClick ();
}
}