Java的键盘/鼠标活动(即使不在我的应用程序) [英] Java Keyboard/Mouse activity (even outside of my app)

查看:176
本文介绍了Java的键盘/鼠标活动(即使不在我的应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测当鼠标或键盘活动是present。我的应用程序在后台(托盘)上运行,我需要检测这一活动,即使我的应用程序是没有焦点。

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.

我也不需要知道哪些键是pressed,只是当他们是pressed。

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

我能做到这一点,只需Java的?我已阅读使用JNI和C ++ / C的一些解决方案,但他们似乎是操作系统特定的。有没有简单的解决方案,这一点,可以在Windows,Linux和Mac?

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?

谢谢!

推荐答案

由于JNI是必需的,这relys上的操作系统特定的API,唯一的方法是 为每个支持的操作系统的实现,并在你的应用程序检测到操作系统后,动态加载它。

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.

对于Windows 的Java全局键盘/鼠标钩子 - JNI

For Windows Java Global Keyboard/Mouse Hook – JNI

这篇关于Java的键盘/鼠标活动(即使不在我的应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆