0

I'm trying to build some robot class in JAVA.
I need to robot hold 3 keys at the same time -> (CTRL + SHIFT + DELETE)
I have to achieve this beacuse this accelerator opens a new windows and saves a lot of time.

Here is my code below:

  Robot robot = new Robot();

            robot.keyPress(InputEvent.CTRL_MASK);
            robot.delay(100); 
            robot.keyPress(InputEvent.SHIFT_MASK); 
            robot.delay(150);
            robot.keyPress(KeyEvent.VK_DELETE);

            robot.keyRelease(KeyEvent.VK_DELETE); 
            robot.keyRelease(InputEvent.SHIFT_MASK); 
            robot.keyRelease(InputEvent.CTRL_MASK);
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76

1 Answers1

2

Basically you need to use KeyEvent constants not InputEvent

        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_SHIFT); 
        robot.keyPress(KeyEvent.VK_DELETE);

keypress is working with KeyEvent constants. Input Events do not belong.

It is all in the documentation http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#keyPress(int)

odedsh
  • 2,594
  • 17
  • 17