0

I'm struggling to figure out how to stimulate a left click in java, any help appreciated!

Here is my code:

Robot KeyPresser = new Robot();
KeyPresser.???

The only things that show after InputEvent for me are InputEvent.mouseInputEvent or InputEvent.keyInputEvent

A.Tol
  • 33
  • 1
  • 8
  • 3
    Why don't you try the [documentation](https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#mousePress(int))? – shmosel Aug 26 '16 at 21:49
  • I did, but for some reason if I put KeyPresser.mousePress(BUTTON1_DOWN_MASK) it throws BUTTON1_DOWN_MASK cannot be resolved or is not a field. And yes it even does so after putting KeyEvent or InputEvent prior to it – A.Tol Aug 26 '16 at 21:54
  • Please [edit](http://stackoverflow.com/posts/39175038/edit) your question to clarify the problem. Did you make sure to import `java.awt.event.InputEvent`? – shmosel Aug 26 '16 at 21:55

1 Answers1

1

I suggest you to check for documentation, it's available. here and here here is an example of how to use robot

    try{

    Robot robot = new Robot();
    // mouse move
    robot.mouseMove(x,y);// x,y are cordinates 
    // Simulate a mouse click
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    // Simulate a key press
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);

} catch (AWTException e) {
    e.printStackTrace();  
}
Community
  • 1
  • 1
whyn0t
  • 301
  • 2
  • 14
  • Thanks, I did already know this but for some reason BUTTON1_MASK shows as an incorrect field. – A.Tol Aug 26 '16 at 22:01
  • The only things that show after InputEvent for me are InputEvent.mouseInputEvent or InputEvent.keyInputEvent – A.Tol Aug 26 '16 at 22:02