Java 键盘/鼠标活动(甚至在我的应用程序之外)

发布于 2024-09-14 07:28:02 字数 220 浏览 1 评论 0原文

我需要检测鼠标或键盘活动何时存在。我的应用程序在后台(托盘)运行,即使我的应用程序未处于焦点状态,我也需要检测此活动。

我不需要知道按下了什么键,而只需知道按下它们的时间。

我可以只使用 Java 来完成此操作吗?我读过一些使用 JNI 和 C++/C 的解决方案,但它们似乎是特定于操作系统的。是否有一个适用于 Windows、Linux 和 Mac 的简单解决方案?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-09-21 07:28:02

由于需要 JNI,而 JNI 依赖于操作系统特定的 API,因此唯一的方法是
为每个受支持的操作系统都有一个实现,并在检测到应用程序中的操作系统后动态加载它。

对于 Windows
Java 全局键盘/鼠标挂钩 – JNI

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文