The following code will result in typing a 'ß' instead of a '-' on MAC OSX 10.10 with Java 7. Any ideas about how to solve this are welcome.
public static void main(String[] args) {
try {
String cmd = "open /Applications/TextEdit.app";
Runtime.getRuntime().exec(cmd);
Robot robot = new Robot();
robot.delay(2000);
robot.keyPress(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_MINUS);
} catch (AWTException | IOException e) {
e.printStackTrace();
}
}
It's not clearly spelled out, but the Javadoc for the keyPress
method is phrased in terms of "keycodes", which normally means that it's mapping to a specific physical key on the keyboard, which the operating system then interprets as some key event (such as "hyphen" or "double S").
The standard German layout has the double S on the key two left of the backspace, which is the hyphen/minus on a QWERTY keyboard.
As for how to solve this, you apparently need to be aware of the keyboard layout. There's a library called Window Licker that's supposed to handle layout issues with the Robot.