I'm attempting to perform a mouse click in Java, to click something in an external program. To do this, I'm using java.awt.robot
, and the following code:
Robot bot = new Robot(); int mask = InputEvent.MOUSE_BUTTON1_DOWN; bot.mouseMove(x, y); bot.mousePress(mask); bot.mouseRelease(mask);
Here's the problem. The external program is able to detect that this click is computer-generated and not human-generated, and hence, its rejecting this click.
I have already tried moving the mouse there naturally and that didn't have any effect. So my guess is, that it must be listening to the keyboard state or such, and telling from that, that the click is computer generated.
What do I have to do to set all keyboard / mouse states to act in the same way as a normal mouse click would?
Well I had the same exact requirement, and Robot class is perfectly fine for me. It works on windows 7 and XP (tried java 6 & 7).
public static void click(int x, int y) throws AWTException{ Robot bot = new Robot(); bot.mouseMove(x, y); bot.mousePress(InputEvent.BUTTON1_DOWN_MASK); bot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); }
May be you could share the name of the program that is rejecting your click?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With