如何使用机器人库来按下:{ 或者 }

huangapple go评论73阅读模式
英文:

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>



huangapple
  • 本文由 发表于 2020年8月24日 08:42:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63553351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定