Global keylogger in 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?
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
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.
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
精彩评论