How can I simulate a mousePressed event without using java.awt.robot?

Jesse picture Jesse · Apr 3, 2011 · Viewed 10.1k times · Source

I want to simulate a mousePressed event in Java, I found out that I can use the Robot class for this, and it works, but only in Windows and not in Mac OS X.

Does anyone know of an alternative way to simulate a mousePressed event?

This is the code I used:

Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);

Answer

javanna picture javanna · Apr 3, 2011

If you want to simulate the click action on a JButton you can invoke the doClick method, take a look here. Otherwise, maybe this similar question can help you. Hope this helps.