0

I am trying to type a semicolon using the Java Robot class but it is not functioning properly. It simply will not type anything and it causes me to highlight everything I click after the program ends. Does someone know why this is not working?

Here is my code:

  public class tEST {

    public static void main (String []args) throws AWTException {

        Robot robot=new Robot();
        robot.delay(2000);

        robot.keyPress(KeyEvent.VK_SHIFT);

        robot.keyPress(KeyEvent.VK_COLON);
        robot.keyRelease(KeyEvent.VK_COLON);

        robot.keyRelease(KeyEvent.VK_SHIFT);
    }
}
ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
user3341249
  • 73
  • 1
  • 11

2 Answers2

1

If you're looking for the semicolon, look instead for:

robot.keyPress(KeyEvent.VK_SEMICOLON);

rather than the combination of keys (different keyboards have different layouts).

Documentation link:

http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html#VK_SEMICOLON

AntonH
  • 6,359
  • 2
  • 30
  • 40
0

The correct KeyEvent constant for semicolon is VK_SEMICOLON

robot.keyPress(KeyEvent.VK_SEMICOLON);
Franky
  • 323
  • 2
  • 10