开发者

Mac OSX Java: Receive mouse events when not activated

开发者 https://www.devze.com 2023-01-01 09:52 出处:网络
I am writing a Java Swing application that needs to have a window receive mouse movement events when the application is not activated - think of it like a global always-on-top toolbar that animates wh

I am writing a Java Swing application that needs to have a window receive mouse movement events when the application is not activated - think of it like a global always-on-top toolbar that animates when the mouse passes over it.

From my research so far, I have seen that the Mac Java JRE only passes events when the application has focus.

It does not appear to be a limitation of the OS, so I was hoping that there was a system property, an application package property or a system call that enabled non-activated event handling. Failing that, some method of globally capturing mouse movement events and passing them in to the Java application.

Thanks for any suggestions...

Edit: One further question: Once mouse move events have been captured, how do you feed them开发者_如何学Python into Swing so that they are treated in the same was as native OS mouse events -- by finding the component under the mouse and sending a MouseEvent to it...


This isn't possible with pure Java.
You will need JNI and to write a global keylistener (or a keyboard hook) in C++ or another language.

Here are some topics about Global KeyListener:

  • Coderanch.
  • My own topic on Stack Overflow
  • Stack Overflow
  • Keyboard hooks in Mac OS X

On the last topic: this was a given solution for OSX.

0

精彩评论

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