Java 中的全局键盘记录器
我正在编写一个监视用户的鼠标和键盘的应用程序。如果他们已经 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要一些 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
如果您只想为您的应用程序执行此操作,那么它非常简单。您可以简单地添加侦听器,即
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.
如果您只想监视 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