XliteRSPS
XliteRSPS

Reputation: 106

Catching KeyEvents Outside of Program

I was wondering if there is anyway to catch a KeyEvent outside of my Java program. I know that using the normal Java, you can only catch KeyEvents that are inside your Java program. From what I have read about this on different forums, I think that catching KeyEvents outside your program is all OS based but i'm using a Windows 7 if that helps anyone. If anyone knows how to achieve this, please answer back and if you don't mind a link too a tutorial or an example would be awesome. Thanks in advance.

Upvotes: 2

Views: 2082

Answers (1)

eboix
eboix

Reputation: 5131

This question might help:

Java Keyboard/Mouse activity (even outside of my app)

It's not an exact duplicate, because it just wants to know whether or not there have been key events, but it gives you a pointer as to what to do:

Use JNI.


In addition:

The code in the link in the question http://www.jotschi.de/?p=90 doesn't work in Windows 7/Vista, but there is a newer version:

http://ksquared.de/blog/2011/07/java-global-system-hook/

And this, I think (I haven't looked at it in depth) is a nice tutorial.

It has ALL of the code you need for this.

Upvotes: 1

Related Questions