Reputation:
I'm writing a syntax highlighting text editor in Java and I've run into a bit of a problem as to what I should do as opposed to what I want to do. Basically the KeyEvent class provides me with a bit of a problem:
My solution to the issue is to use KeyPressed for all characters that are to be input, consume the event, read the character that was supposed to be input and manually input it, however I'm guessing this isn't the most elegant solution available. My question is how else could I go about this? Is there something I'm just glazing over or did I find the solution to my problem and should just roll with it?
Upvotes: 0
Views: 318
Reputation: 1391
The JavaDoc appears to be the opposite of what you say for KeyEvent:
The getKeyChar method always returns a valid Unicode character or CHAR_UNDEFINED. Character input is reported by KEY_TYPED events: KEY_PRESSED and KEY_RELEASED events are not necessarily associated with character input. Therefore, the result of the getKeyChar method is guaranteed to be meaningful only for KEY_TYPED events.
Upvotes: 1