0

I am trying to figure out why I'm getting this exception.

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid combination of button flags

The code is simple. I am using a Robot class named Robot. I am trying to make it so the Robot will left click every 1 second as a test. However, I am having problems getting it to recognize the left click mouse button.

public void click() {
    try {
        robot = new Robot();
        robot.setAutoDelay(1000);
        robot.mousePress(MouseEvent.BUTTON1);
        robot.mouseRelease(MouseEvent.BUTTON1);

    } catch (AWTException e) {
        e.printStackTrace();
    }
}

I've read a few StackOverflow questions and they recommend using the getButtonMask() function, yet my library does not include that function.

Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
Will
  • 1
  • 2

1 Answers1

1

You should use InputEvent instead of MouseEvent eg:

robot.mousePress(InputEvent.BUTTON1_MASK);
Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32