javainputawtrobot

Java simulate keyboard INT input (Robot)


I'd like to simulate the "0" number input in Java, i've heard about Robot but can they also simulate int input? Actually i know only this shortcode:

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end, but i want to enter "0"  before and after press enter...
robot.keyRelease(KeyEvent.VK_ENTER);

Solution

  • Simply use

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

    There is no way to "truly" simulate that an integer comes from the keyboard. The keyboard delivers ascii characters, and it doesn't know which once that qualify as integers.