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

删除回忆录丶 提交于 2019-12-05 07:54:12
Stephen Martin

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.

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.

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

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

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