Java 中的全局键盘记录器

发布于 2024-08-10 19:28:29 字数 116 浏览 8 评论 0原文

我正在编写一个监视用户的鼠标和键盘的应用程序。如果他们已经 1 分钟没有使用键盘或鼠标,则会弹出一条消息,显示“您已经 1 分钟没有使用鼠标或键盘”以及“确定”按钮。

我如何在 Java 中执行此操作?

I'm writing an application that monitors the person’s mouse and keyboard. If they have not used the keyboard or mouse for 1 minute, it will pop up a message that says “You have not used the mouse or keyboard for 1 minute” along with an OK button.

How do I do this in Java?

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

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

发布评论

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

评论(3

我不会写诗 2024-08-17 19:28:29

您需要一些 C/C++ 代码并调用 < code>SetWindowsHookEx 此函数允许您挂钩 Windows 事件并接收副本。

此问题包含帮助您入门的代码:Windows 中的 JNA 键盘挂钩

You need a bit of C/C++ code and call SetWindowsHookEx This function allows you to hook into Windows events and receive a copy.

This question contains code to get you started: JNA Keyboard Hook in Windows

淤浪 2024-08-17 19:28:29

如果您只想为您的应用程序执行此操作,那么它非常简单。您可以简单地添加侦听器,即 Toolkit.getDefaultToolkit.addAwtEventListener(..)

但对于整个系统来说,恐怕无法用java来完成,不过你可以使用JNI。

If you want to do this for only your application, then its very simple. You can simply add listerns i.e Toolkit.getDefaultToolkit.addAwtEventListener(..).

But for the system as a whole, I am afraid, it cannot be done in java, you may use JNI though.

ˉ厌 2024-08-17 19:28:29

如果您只想监视 Java 应用程序窗口中的活动,那么这很简单 – 您所要做的就是注册适当的事件。

但是要监视操作系统中的所有鼠标和键盘活动,您必须连接到依赖于平台的 API,并且需要使用 JNI

If you only want to monitor activity in Java application windows, it's trivial – all you have to do is register to the appropriate event.

But to monitor all mouse and keyboard activity in the OS you will have to hook to the API which is platform dependent and will require using the JNI

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