在一个按钮操作中,我试图添加一个按键。
try{
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.mousePress(KeyEvent.BUTTON1_MASK);
robot.mouseRelease(KeyEvent.BUTTON1_MASK);
}catch(Exception e){}现在我想要"A-Key“按住,在这种情况下,我注释掉了第三行
robot.keyRelease(KeyEvent.VK\_A);但是按键不需要keyRelease.So,我没有拿到“A”键。在另一种情况下,按mousePress直到mouseRelease不execute.Can任何人给我解决方案或解释发生了什么。
发布于 2012-07-27 22:10:49
请看一个类似的问题,它的答案使用Thread.sleep()来保持按键:Simulate a key held down in Java和这个问题:How can I make Robot press and hold a mouse button for a certain period of time?
https://stackoverflow.com/questions/11689291
复制相似问题