本文介绍了我怎样才能让机器人输入一个`:`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Java Robot键入:
。但是,我得到一个 IllegalArgumentException
。我的代码是:
I want to type :
using Java Robot. However, I'm getting an IllegalArgumentException
. My code is:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_COLON);
robot.keyRelease(KeyEvent.VK_COLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
例外是:
java.lang.IllegalArgumentException: Invalid key code.].
我也尝试过:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
如何解决这个问题?
推荐答案
尝试使用此代码:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
与您输入的键盘一样:当您按shift + ;.同样你需要模拟。
As with the keyboard you enter : when you press shift + ;. the same you need to simulate.
尝试运行此代码只是为了尝试哪种方法可以正常使用以上答案:
Try running this code just to try out which works fine with above answer:
public class Test {
public static void main(String[] args) {
Robot robot;
try {
robot = new Robot();
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
} catch (AWTException e) {
// TODO Auto-generated catch bloc
e.printStackTrace();
}
}
}
这篇关于我怎样才能让机器人输入一个`:`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!