我正在使用java自動鍵入事物。這是我寫的:無效的密鑰代碼@ java
public void typeMessage(String message) {
for (char c : message.toCharArray()) {
int code = c;
if (code > 96 && code < 123)
code = code - 32;
if (c == '@') {
robot.keyPress(VK_SHIFT);
robot.keyPress(VK_AT);
robot.keyRelease(VK_SHIFT);
robot.keyRelease(VK_AT);
} else {
type(code);
}
}
type(VK_ENTER);
}
但我發現了這個錯誤:
Exception in thread "Thread-2" java.lang.IllegalArgumentException: Invalid key code
上
robot.keyPress(VK_AT);
http://stackoverflow.com/questions/6634375/why-are-some-keyevent-keycodes-throwing-illegalargumentexception-invalid-key-c的可能重複 –
我想你可以參考:http://stackoverflow.com/questions/11923033/java-awt-robot-keypress-throws-illegalargumentexception-when-when-pressing-quota –