Java Robot Class KeyPress

时间:2013-04-28 12:07:50

标签: java keyevent awtrobot

代码

Robot r=new Robot();
r.keyPress(KeyEvent.VK_CAPS_LOCK);
r.keyPress(KeyEvent.VK_V);
r.keyPress(KeyEvent.VK_CAPS_LOCK);
打印V后,

不会关闭。我该如何解决?

1 个答案:

答案 0 :(得分:3)

按下后必须释放按键:

Robot r=new Robot();
r.keyPress(KeyEvent.VK_CAPS_LOCK);
r.keyRelease(KeyEvent.VK_CAPS_LOCK);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_V);
r.keyPress(KeyEvent.VK_CAPS_LOCK);
r.keyRelease(KeyEvent.VK_CAPS_LOCK);