title: Java Robot class mouse move to position of a specific pixel (Mouse click a color)
body: <p>How to find the position of a color that is changing coordinates and needs to be click after being identified.</p>
  
  <p>Purpose of the program complete tasks in a game, requiring the clicking of different colors which aren't always in the same position.</p>
  
  <p>Code currently gets color of mouse's coordinates after 5 seconds of executing program</p>
  
  <hr>
  
  <pre><code>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 ();
      }
  }
  </code></pre>