Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 655
Jesse Avatar asked Dec 07 '25 02:12

Jesse


1 Answers

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.

like image 186
javanna Avatar answered Dec 08 '25 14:12

javanna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!