Global keylogger in Java

偶尔善良 提交于 2019-12-17 17:09:47

问题


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?


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1714349/global-keylogger-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!