开发者

Java robot class

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:

publi开发者_如何转开发c 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?


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)


Robot expects key codes defined in KeyEvent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜