2013-03-28 53 views
1

如何找到正在改变坐标的颜色的位置,需要在识别后点击。爪哇机器人类的鼠标移动到特定像素的位置(鼠标点击一种颜色)

程序的目的完成游戏中的任务,需要点击不总是在相同位置的不同颜色。

代码当前执行的程序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(); 
    } 
} 
+0

[高级系统活动](http://sourceforge.net/p/javaxsystem/wiki/Home/#dcf7)可能对您有所帮助。 – Visruth

回答

0

你很可能需要采取的截屏图像,然后旋出(假设“颜色”正在后得到鼠标的坐标的颜色一个连续的路径,而不是跳过)从原始位置比较该像素的颜色和您正在寻找的颜色。一旦确定后,请执行mouseMove(newX, newY),然后执行mousePress()/mouseRelease()方法。