问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/15910105/make-a-fake-mouse-in-java