如何使Robot按住鼠标键一定时间? [英] How can I make Robot press and hold a mouse button for a certain period of time?
本文介绍了如何使Robot按住鼠标键一定时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Java通过Robot类生成鼠标按下:
I am using Java to generate a mouse press using the Robot class:
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
但是,我希望机器人在一定时间内按下按钮.我该如何实现?
However, I want the Robot to press the button for a certain period of time. How can I achieve this?
推荐答案
在两个操作之间只睡一会儿(以毫秒为单位):
Just sleep a bit between the two actions (specified in milliseconds):
-
Thread.sleep(long millis);
Thread.sleep(long millis);
robot.mousePress(InputEvent.BUTTON1_MASK);
try { Thread.sleep(1000); } catch(Exception e) {} // Click one second
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Robot.delay(long millis);
Robot.delay(long millis);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(1000); // Click one second
robot.mouseRelease(InputEvent.BUTTON1_MASK);
这篇关于如何使Robot按住鼠标键一定时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文