Java.awt.robot mousepress is not having any effect

南楼画角 提交于 2019-12-11 13:53:56

问题


I'm trying to simulate a left click in a different program using awt.robot, with the following code:

int mask = InputEvent.BUTTON1_DOWN_MASK;
bot.mouseMove(x, y);   
bot.mousePress(mask);
bot.mouseRelease(mask);

While this is moving the mouse to the correct part of the screen, the other program doesn't seem to be receiving the click. What am I doing wrong?

In certain other programs, this same method produces the click, but in one program, it has no effect.

I have tried Thread.sleep() to wait 30-300 milliseconds between mouseMove and mousePress, but it had no effect.

Do I need to use JNI and native windows API to achieve this? I'm on Windows 8.


回答1:


You are using the wrong mask: InputEvent.BUTTON1_MASK




回答2:


Have you tried a bot.delay(n) between bot.mousePressed(mask) and bot.mouseReleased(mask)?



来源:https://stackoverflow.com/questions/19168945/java-awt-robot-mousepress-is-not-having-any-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!