Wednesday, 7 August 2013

Robot class - If a Button Is Pressed?

Robot class - If a Button Is Pressed?

I have read and understood how the Robot class in java works. Only thing I
would like to ask, is how do I press and release the mouse button inside
an if statement. For example I would to make a click only if (and right
after) the space button is pressed/released. I would use the code:
try {
Robot robot = new Robot();
if (/*insert my statement here*/) {
try {
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (InterruptedException ex) {}
}
} catch (AWTException e) {}

No comments:

Post a Comment