title: Robot class - If a Button Is Pressed?
body: <p>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:</p>
  
  <pre><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) {}
  </code></pre>