开发者

Detecting a Mouse Click Anywhere on Screen with Java

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 li开发者_如何学Cke 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜