java.awt.Robot - Stimulate Key Press Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xirowei
    New Member
    • Jun 2007
    • 17

    java.awt.Robot - Stimulate Key Press Not Working

    Dear All,

    I had google for example how to use java.awt.Robot class. I also read Java Document regarding of awt.Robot class. When I test below code, I get error message "cannot find symbol method delay(int)" and "cannot find symbol method keyPress (int)". May I know what is my problem?

    *Installed JDK Version 6 update 21

    Code:
    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    
    public class MyRobot
    {
        public static void main (String [] args)
        {
            try {
                MyRobot myrobot = new MyRobot();
                
                myrobot.delay(3000);
                myrobot.keyPress(KeyEvent.VK_T);
                myrobot.keyPress(KeyEvent.VK_E);
                myrobot.keyPress(KeyEvent.VK_S);
                myrobot.keyPress(KeyEvent.VK_K);
                
            } catch (AWTException e) {
                e.printStackTrace();
            }
        }
    }
  • Ian Smith

    #2
    try

    Code:
    import java.awt.*;
    import java.awt.event.*;
    And

    Code:
    Robot myrobot = new Robot();
    Last edited by Niheel; Sep 27 '10, 08:30 PM.

    Comment

    • xirowei
      New Member
      • Jun 2007
      • 17

      #3
      Dear Ian Smith,

      I try your solution and it works! The main issue in my code is:

      //Incorrect code
      MyRobot myrobot = new MyRobot();

      //Correct code
      Robot myrobot = new Robot();

      Comment

      Working...