Detecting a Mouse Click Anywhere on Screen with Java

非 Y 不嫁゛ 提交于 2019-12-31 05:15:10

问题


Is it possible to detect a mouse click anywhere on a screen, outside of my application?

I have written an application to do this in C#, but would like to write a version of this in Java so that it can be run on several platforms.

It looks like I can get the co-ordinates of the mouse at any time with java.awt.MouseInfo.getPointerInfo() but I am not sure as to how to listen for a mouse click.

In C# I used GetAsyncKeyState to detect whether the mouse button was clicked, but obviously I cannot use this if I wish to keep this "clean" for use in multiple platforms.


回答1:


You can do this only with platform specific implementation of the OS API, as you can't detect clicks outside from your program in your program itself.

While you won't get around writing platform specific code, just abstract it as an interface and use different implementations appropiately.



来源:https://stackoverflow.com/questions/4869294/detecting-a-mouse-click-anywhere-on-screen-with-java

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