I am writing a basic program that asks the user to type in a String, and I am trying to use a Robot (from java.awt.Robot)that will type this message back into a
You could work something out with this:
KeyStroke ks = KeyStroke.getKeyStroke('k', 0);
System.out.println(ks.getKeyCode());
or just use this:
private void writeString(String s) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isUpperCase(c)) {
robot.keyPress(KeyEvent.VK_SHIFT);
}
robot.keyPress(Character.toUpperCase(c));
robot.keyRelease(Character.toUpperCase(c));
if (Character.isUpperCase(c)) {
robot.keyRelease(KeyEvent.VK_SHIFT);
}
}
robot.delay(delay);
}