本文介紹了無效的鍵碼@java的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在開發(fā)一個(gè)使用 java 自動(dòng)輸入內(nèi)容的系統(tǒng).我是這樣寫的:
I'm working on a system to type things automatically with java. This is how I write it:
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);
}
但是我收到了這個(gè)錯(cuò)誤:
But I'm getting this error:
Exception in thread "Thread-2" java.lang.IllegalArgumentException: Invalid key code
在
robot.keyPress(VK_AT);
推薦答案
你的鍵盤布局應(yīng)該有一個(gè)@符號(hào)的鍵,這樣代碼才能工作.是嗎?
Your keyboard layout should have a key for the @ symbol for this code to work. Does it?
如果您的鍵盤設(shè)置為美式布局,您需要輸入 shift+2 來輸入 @ 符號(hào),而您必須使用 VK_2 而不是 VK_AT.
If your keyboard is set up with an American layout you need to type shift+2 to type an @ symbol, and instead of VK_AT you have to use VK_2.
這篇關(guān)于無效的鍵碼@java的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!