I would like to simulate a Enter key press. I tried using the robot class but it doesn't seem to work:
robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
try{Thread.sleep(50);}catch(InterruptedException e){}
robot.keyRelease(KeyEvent.VK_ENTER);
In my main code, I have
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
System.out.println("ENTER KEY PRESSED");
// DO SOMETHING;
}
}
so if the keyPress is registered, then the console should print out "ENTER KEY PRESSED", but it's not doing that.
Thanks for your help!
Also if you know a way to simulate key events without robot class, please post below :).