Java Keyboard/Mouse activity (even outside of my app)

隐身守侯 提交于 2020-01-11 05:23:07

问题


I need to detect when the mouse or keyboard activity is present. My application runs in the background (tray) and I need to detect this activity even when my app isn't in focus.

I don't need to know what keys were pressed, but simply WHEN they are pressed.

Can I do this with just Java? I have read some solutions using JNI and C++/C but they seem to be OS specific. Is there an easy solution to this that will work with Windows, Linux, and Mac?

Thanks!


回答1:


Since JNI is required, which relys on the OS specific APIs, the only way would be to have an implementation for each supported OS and load it dynamically after detecting the OS in you application.

For Windows Java Global Keyboard/Mouse Hook – JNI



来源:https://stackoverflow.com/questions/3490469/java-keyboard-mouse-activity-even-outside-of-my-app

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