From JavaDoc:
void java.awt.Robot.keyPress(int keycode) Presses a given key. The key should be released using the keyRelease method.
EDIT: adding sample:
Robot robot = new Robot(); System.out.println("You have 2 seconds to jump to the target window..."); Thread.sleep(2000); robot.keyPress( KeyEvent.VK_A); robot.keyRelease( KeyEvent.VK_A); robot.keyPress( KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_A); robot.keyRelease( KeyEvent.VK_SHIFT); robot.keyRelease( KeyEvent.VK_A); Thread.sleep(2000);
Exit to the target window:
aA
(I know that this is not what you want, but I added it as a reference for future readers, so they donβt think there is an error in JavaDoc or Robot)
source share