Reputation: 3334
I have a problem with typing in Robot Class. I want the robot to type something the user has entered. The robot for some reason can't type some of the characters. Here is my type code:
public void type(String s,Robot robot) {
byte[] stringBytes = s.getBytes();
for (byte b : stringBytes) {
int code = b;
if (code > 96 && code < 123)
code = code - 32;
robot.keyPress(code);
robot.keyRelease(code);
}
}
how can i fix this problem?
Upvotes: 1
Views: 757
Reputation: 3207
If you want to "type back what the user entered", then surely you should be capturing a set of KeyEvent
objects, and not a String
. There is not a key for every String
character, far from it! (for instance you need to press 'shift' to input a colon, so that's two key presses and not one)
Upvotes: 2