简体   繁体   English

使用awt包中的Robot类的双击事件

[英]Double click event using Robot class in awt package

I have already seen lot of threads regarding double click events using MouseEvent . 我已经看到很多有关使用MouseEvent进行双击事件的线程。 But that is not what I am looking for. 但这不是我想要的。 I recently started using Robot class and came across few functions of mouse like mouseMove(x,y) , mouseRelease(int buttons) . 我最近开始使用Robot类,并遇到了mouseMove(x,y)mouseRelease(int buttons)类的一些鼠标功能。

Robot class provides mousePress(int button); Robot类提供mousePress(int button); function as well. 以及功能。 I have tried this. 我已经试过了。

Robot robot = new Robot();
robot.mouseMove(305, 450);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

But this is a single click event. 但这是一个单击事件。 What I am trying to achieve is the double click event using Robot class. 我想要实现的是使用Robot类的双击事件。 Is it possible to achieve that ? 有可能实现这一目标吗? If so. 如果是这样的话。 then how ? 那又如何?

The Robot class doesn't provide a way of double-clicking. Robot类不提供双击方式。 You'll have to implement that yourself. 您必须自己实现。 Think about what a double-click really is, it's two clicks in quick succession. 考虑一下真正的双击是两次连续快速的单击。 (Depending on your OS settings, the required time between clicks might vary.) (取决于您的操作系统设置,两次单击之间所需的时间可能有所不同。)

So you really just need to click twice really quickly: 因此,您实际上只需要快速单击两次即可:

Robot robot = new Robot();
robot.mouseMove(305, 450);
// first click
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
// second click
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

You might also want to add a few milliseconds of delay between the two clicks, as some things might not respond well to too-fast clicks. 您可能还希望在两次点击之间添加几毫秒的延迟,因为某些事情可能无法很好地响应过快的点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM