1 Reply Latest reply: Jun 25, 2010 12:02 PM by Darryl Burke RSS

    Continue after Robot has finished typing

    843807
      Hi,

      I have found a basic example of the Robot class:
      public class RobotExample {    
          public static void main(String[] args) {        
              try {            
                  Robot robot = new Robot();
                  // Robot start writting
                  robot.keyPress(KeyEvent.VK_H);
                  robot.keyPress(KeyEvent.VK_I);
                  robot.keyPress(KeyEvent.VK_SPACE);
                  robot.keyPress(KeyEvent.VK_B);
                  robot.keyPress(KeyEvent.VK_U);
                  robot.keyPress(KeyEvent.VK_D);
                  robot.keyPress(KeyEvent.VK_Y);            
              } catch (AWTException e) {
                  e.printStackTrace();
              }
          // Code that follows needs to ensure that the Robot has finished typing
          }
      }
      The code that immediately follows the Key Presses remove focus from where the robot is typing so it would be nice to detect when the Robot has finished typing before I continue. At the moment the best way I can think of would be to simply place all the Key Presses in a Thread, telling it to sleep once it had finished. The problem with that is there could still be a problem with the amount of time being too much or too little and no way of finding out.

      Does any one have any ideas how I can listen to the Robot events and continue once they have finished?

      Thanks