Manish
Manish

Reputation:

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?

Upvotes: 2

Views: 5196

Answers (3)

Aaron Digulla
Aaron Digulla

Reputation: 328724

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

Upvotes: 4

Alon
Alon

Reputation: 4952

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

Upvotes: 0

Suraj Chandran
Suraj Chandran

Reputation: 24791

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.

Upvotes: 3

Related Questions