Where it says **spacebarpressed**
, I want to cast an event:
public static void main(String[] args) throws IOException, AWTException{
final Robot robot = new Robot();
robot.delay(2000);
while(true)
{
if( **spacebarpressed** ) {
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(50);
}
else {
robot.delay(50);
}
}
}
You want to check if spacebar is pressed? If that's so, you need an inner private class that implements
KeyListener
, but you need to hook it up to aJFrame
however... I don't know about any other way.And then just call
isSpacebarPressed()
in your while loop to check.