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

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).

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

Related

How can I send DPAD_LEFT/DPAD_RIGHT key events from my app to the active activity?

I want to send DPAD key events from my service to the active activity.
This is not a commercial app, and I won't distribute it. It is only for my own use. So any suggestion which does not include "root"ed devices , I can use.
I can do it with ADB using commands like "KEYCODE_DPAD_DOWN_LEFT"
however, this is not available for a normal app. (I tried runtime.exec) it's not permitted.
How can I achieve this with any method ? (accessibility, special permissions , etc.)
thanks.

Android service and native threads

Given the limitations that are being imposed on background services in later versions of Android, how do you accomplish the following:
The application's JAVA background service and the native C++ threads which are started by the JAVA background service via JNI continue to run regardless of the phone's state (screen on or off) and regardless of the application's state (activity life cycle). If an activity has been destroyed, the background service must continue to run.
If the user clears the application from the task list (menu button), the background service continues to run and so does the C++ threads.
If the user presses the menu back button, the background service continues to run and so does the C++ threads.
If the user navigates to the OS settings (applications) and selects FORCE CLOSE/STOP for the application, then the application AND the background service is stopped/destroyed.
One of the native threads is responsible for listening and processing UDP data via a socket that listens for multicast data. It is critical that this continues to work regardless of phone/app state (unless the app is forcefully closed).
Not sure if I get your problem right, but all these points you mention, one can accomplish by using the Android Service Component like describede here: https://developer.android.com/guide/components/services.html
I worked with this some time ago and it did just these points you require.
Please correct me if I'm wrong.

Remote access to Java Swing application screen with interaction

Does anyone know if there's a way to provide remote access from a client to a Swing application running on a server? This question also involves how to redirect the screen output on the remote server to a file or process, as it may be a headless environment.
What I want roughly is this:
the user on the client starts up an application on the server
the application's screen output is routed to 'something' which sends it over to the client
the user on the client can tap on the screen indicating mouse clicks and can optionally bring up a keyboard for keyboard input (obviously keyboard will only work if the user previously focused something on the remote app
(I'm especially interested in doing this using iOS as client platform.)

Monitor All Android Devices events remotely

In Android, I can monitor if certain events are triggered through the use of Broadcast Receivers. Are there any tools which let me view ALL events on an android device I am debugging instead of having to add a broadcast receiver to listen to them?
For example, in a Broadcast receiver, I can monitor for a call forwarding event. Is there a way to debug such events outside of having to write additional Android code? My goal is to test that certain events are triggered after UI state changes, and I am not seeing anything obvious in Logcat that communicates which events are being fired.
For example,
with call forwarding I only see cases like below in Logcat.
START u0 {act=android.intent.action.MAIN cmp=com.android.phone/.GsmUmtsCallForwardOptions}
The machine where you run an Android remotely can be any system supported by the Android SDK: Windows, Mac OS X, or Linux. The socket connections is forward from a specified local port to a specified remote port on the device instance.
It is recommended that this machine is on the same network as your development PC, for performance and configuration reasons, but it is also possible to use any remotely located machine if firewalls and routing are configured correctly. You have to follow specified steps that provide you with the necessary settings in your environment configuration that will allow you to have remote debugging.
Alternatively you can also consider using Google chrome remote debugging for Android. The jsHybugger can also offers you a similar tool that will equally allow Android remote debugging.
Indeed you can choose the approach that suits you better.
Otherwise, if what you meant is to listen to event in some application, then this has to be done by yourself by hand, including it to the respective app you want to listen for every single event. Further details on this direction you find here:
Android listen for all events in application
As you can see, Android has a lot of capabilities, but everything come at some cost - i.e. you have to code it. Otherwise, something that could be done according to your suggestion would be kind of an App or an API that would monitor every single event from all Apps currently in your mobile. But if this is what you really want, then in my view such approach would be cumbersome and overload your mobile.

About a chat client-server program in java

I made a client-server chat that uses a postgresql database to store the users. The server uses comunication protocols designed by me to allow the comunication process and everything works fine. The problem is, the user needs to click on a button in order to open the chat window when he gets the message, otherwise he can't read the incoming message. I would like to program a msn-like service where a window opens when you get a message if the window is not already open and if it's open just show the message in that same window. I can't seem to find a way to do it and any help I can get would really be apreciated. Thanks.
A couple of things you may want to take a look at. First is Java integration with Windows System tray.
http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/
The other is to run a "listener" in the background perhaps as a Windows service.
This service listens for messages and pops them into a window. The window can be dismissed (hidden) without stopping the service. http://edn.embarcadero.com/article/32068

Categories