views:

198

answers:

3

I'm looking to record keystrokes and mouse positions while I'm in a browser window on various websites, but I'm not sure how to do this outside the SWING (or some other GUI) window.

How can I record keystrokes when a different application's window is the one active?

+1  A: 

I don't think you can do this from pure Java. If it is possible at all, it would require the assistance of a (highly) platform specific native code library.

Stephen C
can't do it in Java or can't do it at all? seems to me like a native library might let you get the behavior, though i'm having trouble coming up with any good-intentioned reason for doing it..
Mark E
Would this be doable in C++ on a Windows machine?
Chad
+1  A: 

(Windows only) In theory you could use JNA or JNI to bind to GetAsyncKeyState and you'd be able to monitor key presses.

Mark E
+1  A: 

The support you need is not exposed by Java. It is a fairly simple matter to do this if you have access to the RECORD extension in X, or Win32 on Windows.

Here is a Python project that implements support for both of these platforms: pykeylogger.

Adam Goode
I didn't think of looking at some open source key loggers. Thanks, this is exactly what I need (and it'll let me practice my Python programming skills)
Chad