How to detect user activity using a Java service running on Windows?

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

8:00 - 8:15 activity

9:12 - 10:29 Activity

12:24 - 15:34 activity

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

Is this possible in Java? I plan to run a Java application as a service. But as for receiving events when a user uses a computer, I do not know where to start.


[Edit] Further clarification: I am not interested in the details of the activity, only that the user has moved the mouse or pressed a key. I don’t care which key was pressed, if I know that the key was pressed in the application somewhere. I also do not care about any other activity besides pressing a key and a mouse (for example, I am not interested in whether a USB key is inserted in the USB port).

+6
java windows android-activity windows-services
source share
4 answers

You cannot control user activity directly from the service. The service will work in another window station from user actions and therefore will not be able to connect to this operation (with the exception of filter drivers, which must be written in C).

Thus, you will need a client application that runs on the user's desktop and connects to the keyboard and mouse. This can be done with two calls to the Windows SetWindowsHookEx API (for low-level keyboard and mouse hooks) using JNI. To track activity, the application then needs to process keyboard and mouse message hooks.

You can start the application as autorun by adding an entry to the registry start key, or you can have your own service monitor for the session event log and start the application from it. Then the user session application can either process the information or transmit it to the service through a channel or socket.

+2
source share

What exactly do you mean by "user activity"? You must define this term precisely in order to even start thinking about a solution, especially since you say that “pressing a key, using an application, etc.” are not actions.

+1
source share

You can try this SWT Win32 Extension . This allows you to set keyboard and mouse jumpers from java on windows.

+1
source share

This is not directly supported by the Java platform.

It would be much easier to learn an alternative to .NET.

Find Capturing Global User Input in .net

0
source share

All Articles