• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

simple windows manipulation in Java

JoeCDaMan

Senior member
I am currently involved in writing a non applet based java application for windows. I am trying to mimic a program that someone sent to me, basically what it does is intercept keyboard strokes that the user enters and then displays letters from a predermined string "hi my name is Joe, I have a wife and three kids" The part that I am not able to replicate is the keyboard manipulation outside of the java frame. The orriginal program seemed to work with windows itself effecting all programs within such as microsoft word, aol instant messager, and other text based applications.

I do not know the language that the orriginal application was written, so I am not sure whether or not I can write such an application in java or not. I have been to java.sun.com and have been reading their Java APIs but I am at a loss. I don't know what I need to do to get my program to control keyboard events for other programs. I have been researching focus event listeners to know when the frame is maximized and minimized. From what I can gather though is that the focus event listeners can only be applied to frames that I have written, and that again I can only superimpose keyboard listeners to frames that I have written. Any help that you can provide would be greatly appreciated.

I am most familiar with the java language, so I am not really interested in your oppinions on how Java sucks or it is slow or anything of that nature, but if you could aid me in my problem, I would be most appreciative.

TIA - JoeCDaMan
 
Doesn't really sound like something java could do, sounds a bit low level.

But I'm no expert on it.


So it listens to keyboard strokes and if it sees a certain pattern it prints stuff to whatever application the user is typing from?
 
It's obvious the only way you can do this is via Win32 APIs, which you could access via JNI. Most likely if you had to program the keyboard trapping stuff in Win32 C/C++ you might as well do the whole app in the same language.
 
I think manly is right. It sounds like what you want to do requires hooking into the keyboard handler in order to intercept keystrokes before they are sent to the target window. Java alone won't do this.

You could, however, hook into the keyboard handler using Java Native Interface (JNI) to make Win32 API calls directly. Some good info on JNI can be found here, here, here and here.

Note: the completely destroys the whole Java "write once, run anywhere" philosophy because you are inherently tying yourself to one platform by writing the native code. If you were looking to port the original app to other platforms I don't believe this will work too well for you.
 
Back
Top