Make a “Fake” mouse in java?

一世执手 提交于 2021-02-18 11:41:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!