tags:

views:

344

answers:

7

I have a requirement to be able to track how much a user interacts with the different applications running on their machine. What seemed logical to me was to keep a log of window focus events with timestamps which would tell you what applications were in focus over the course of the day.

We have some other things to do in this application that would be straightforward in Java. However I haven't done any GUI programming in Java so I'm not sure if it's possible to get information about OS-level windows through the awt API. Is that even possible? Would there be another way to do this through JNI or would a native application be required to do this?

PS: I know that this requirement sounds a little nefarious but I am only here to determine whether or not this is technically possible. Please don't shoot the messenger, this wasn't my idea. :)

A: 

I don't think this is possible using AWT. Java has no way of accessing the processes for the other applications.

Mark
+4  A: 

With out resorting to native code I don't think this will be possible.

TofuBeer
+4  A: 

Focus events might work; you might also want to consider Windows keyboard and mouse hooks. With any of these approaches, you'll want to create a DLL (native code) and use JNI to access it.

jdigital
A: 

I think you should consider using another language.
There are other languages like C++ for example that are predistinated for this kind of problems :)

n00ki3
A: 

You're basically asking that your app be included on OS notifications to other applications. You'll probably need to either have an app that launches the other apps as child processes or use something like a rootkit API to establish permissions above what a normal application is granted.

If the goal is to see how much time a user is interacting with your application, you might get some rough ideas by looking at the CPU time being scheduled to your application or some how looking at delays between I/O events and mapping those into stats about how active the user is.

Otherwise, I think you might be able to contact with some spyware developers to get what you need.

Dan
A: 

If you want to do this from Java and don't want to write your own native code, you can try SWT. I doubt it has platform-agnostic ways of accomplishing what you want, but you can poke around in the Windows-specific classes, especially org.eclipse.swt.internal.win32.OS.

Adam Crume
+1  A: 

You might look for a window testing library--some of those are made to create and intercept win32 native events.

Bill K