Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a "Fake" mouse in java?

Tags:

java

awtrobot

In java you can use the Robot Class to move the mouse and fire mouse clicks. While this is cool, it also "hijacks" the users mouse, so you cannot multitask.

What I want to do is make a "Fake" mouse that acts independently of the system's mouse cursor, and lives only inside my java applet. In this sense the applet would think it was being clicked by the mouse in various (x,y) positions (within the applet), however I can do whatever I want with the system mouse and it will not be affected.

I have seen programs that have accomplished this, I just have no idea where to begin. Perhaps I am just using the wrong terminology for this functionality.

Any suggestions on where to look would be much appreciated. -Thanks

like image 813
Tony Depace Avatar asked Apr 09 '13 18:04

Tony Depace


1 Answers

What I want to do is make a "Fake" mouse that acts independently of the system's mouse cursor, and lives only inside my java applet.

Create a Runnable FakeMouse class that fires mouse clicks. Tony Depace provided the code, which I'm adding to the answer to help others.

MouseEvent aClick = new MouseEvent(this, MouseEvent.MOUSE_CLICKED,   
        System.currentTimeMillis(), 0, 10, 10, 1, false); 
dispatchEvent(aClick);

Run the FakeMouse class in a thread in your Java applet.

like image 63
Gilbert Le Blanc Avatar answered Sep 21 '22 14:09

Gilbert Le Blanc