I\'m writing some integration tests using a robot. I have the robot opening a menu and it should be selecting one of the options form the menu; except the enter key seems t
Well, I got stuck on the same issue of pressing the Enter key. Me too, have no explanation when I tried to operate a native OS File Chooser dialogue using Enter in the end and it did not work. But it seems, that the issue can be solved by creating another Robot object where you call the Enter event. So please let me at least assist you or other lone surfers coming across to seek counsel. ;-)
public static void enterKeyIssueTest() {
// both lines put some content to the Clipboard
StringSelection ss = new StringSelection("/fancyUser/tightDir/coolFile.apk");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
// 1st Robot Object
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL); // press Ctrl
robot.keyPress(KeyEvent.VK_V); // and press V
robot.keyRelease(KeyEvent.VK_V); // release Ctrl
robot.keyRelease(KeyEvent.VK_CONTROL); // release V
// 2nd Robot to my avail
Robot okRobot = new Robot();
// presses Enter
okRobot.keyPress(KeyEvent.VK_ENTER); // press Enter
okRobot.keyRelease(KeyEvent.VK_ENTER); // release Enter
}
This is indeed a very small example, but I hope the explanations in the code above will assist. Indeed, the second Robot object did the Enter event for me.
Best regards, Semo