开发者

Check for keystroke

开发者 https://www.devze.com 2023-02-28 11:25 出处:网络
Im making an application that should see if your online or away. So i need to someh开发者_StackOverflow中文版ow see when the user hit a key on the keyboard last time.

Im making an application that should see if your online or away. So i need to someh开发者_StackOverflow中文版ow see when the user hit a key on the keyboard last time. The application is running in the background and you can only access it from the trey.

Is this possible and if it is how would i check.

Best regards


I believe that what you're looking for can be done via a global keyboard hook, but that doesn't have direct support in the JVM. From Googling, it would appear that your only options are to write a C++ shim which you can use via JNI, or go via libffi with JRuby.


From what I've read here it is not possible to add KeyListener to the SystemTray. The only listener that is supported, is the PropertyChangedListener.

Furthermore from that question it seems to be possible on Windows but not on Linux and MacOS.


This is possible, but not using Java. You'll have to use JNI to access OS APIs that provide this information (and implent it differently for each OS).

0

精彩评论

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