英文:
How to use the robot library to press: { or }
问题
我正在尝试制作一个机器人,可以执行诸如输入:“你好”之类的指令。
但是当我尝试使用以下代码:
robot.keyPress(KeyEvent.VK_BRACELEFT);
或者
robot.keyPress(221);
其中之一应该输入:{
但是实际上却抛出了无效按键代码的异常。
那么有人可以告诉我如何输入:{ 和 } 吗?
英文:
I Am tring to do a bot that you put instruccions like say: hello
But when I try to use
robot.keyPress(KeyEvent.VK_BRACELEFT);
or
robot.keyPress(221);
one or the other should press: {
but no it throws me the exception of an invaid key code.
So can anyone tell me how to type: { and }
答案1
得分: 1
你需要使用Shift键和位于其下方的键。Robot类无法访问所有ASCII字符。这里是一个示例:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_OPEN_BRACKET);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_OPEN_BRACKET);
英文:
You would need to use shift and the key that is there underneath it. The Robot class doesn't reach all ascii characters. Here is an example:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_OPEN_BRACKET);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_OPEN_BRACKET);
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论