问题
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