views:

904

answers:

4

My goal is to create a system monitoring application using Java. I would like to know when a user is doing activity on a Windows PC. The result would be something like this:

8:00 - 8:15 activity

9:12 - 10:29 activity

12:24 - 15:34 activity

I'm not interested in any other information (which key was pressed, application used, etc.). Only user activity.

Is this even possible in Java? I plan to run my java application as a service. But as for getting events when a user uses the computer, I have no idea where to start.


[Edit] Further clarifications: I'm not interested in the details of the activity, only that a user has moved the mouse or pressed a key. I don't care which key was pressed, as long as I know that a key was pressed in an application somewhere. I also don't care for any other activity except key pressed and mouse movement (for example, I am not interested if a USB key is inserted in a USB port).

+1  A: 

What exactly do you mean by 'user activity'? You need to define that term precisely first to even start thinking of a solution, especially as you say that "key pressed, application used, etc." are not activities.

talonx
A: 

This is not directly supported by the java platform

It would be a lot easier if you explore a .NET alternative.

Search for Capture global user input in .net

OscarRyz
+1  A: 

You cannot monitor user activity directly from a service. The service will be running in a different window station from the users activities and so will have no way to hook into that activity (except through filter drivers that would need to be written in C).

So you will need a client application that runs in the user's desktop and hooks into the keyboard and mouse activity. You would do that via two calls to the Windows API SetWindowsHookEx (for low level keyboard and mouse hooks) using JNI. To monitor activity the application would then need to process the keyboard and mouse hooks for messages.

You could launch the application as auto-start by adding an entry to the registry's Run key or you could have your service monitor for session log on events and launch the application from it. Then the user session application could either process the information itself or pass it to the service via a pipe or socket.

Stephen Martin
Thanks. After search on Google, I did find some JNI code that uses SetWindowsHookEx () to do what I'm looking for.
Thierry-Dimitri Roy
+1  A: 

You could try this SWT Win32 Extension. It allows you to set keyboard and mouse hooks from java on windows.

Peter Smith