I want to create a program that would run in the background and everytime the user presses a key, the program would notify him in which language he is writing. but I don't know how to detect (if possible) a key pressing in another unrealated program… As far as I know keylisteners are only for my own java program when it has the focus, so it is not that useful for me… (Sorry for my poor english)
Asked
Active
Viewed 192 times
1
-
1You are trying to implement a key logger? – AxelH Dec 04 '17 at 11:25
-
See above. You need to use JNI to accomplish this, which means your code may not be as portable as it would be otherwise. – Michael Dec 04 '17 at 11:26
1 Answers
1
Try JNativeHook, it does this nicely.
Only caveat is that the key codes returned are different from those that Java uses IIRC.
I could show you a working program but Stack Overflow doesn't let me link to it because that would be "advertising". No time to produce an SSCCE for this space right now, sorry. I think JNativeHook is not hard to get into anyway.

Stefan Reich
- 1,000
- 9
- 12