Question

I have a need to get the unicode value for a specific keydown event in GWT. All the references I have seen so far suggest doing something like char c = (char)keyCode however this does not seem to work (Does not produce the char/string I was expecting -- especially when the input is japanese)

My code is as follows:

DOM.setEventListener(documentElement, new EventListener() {

            public void onBrowserEvent(Event event) {
                int keycode = event.getKeyCode();

                   char c=(char)keyCode;     
                   String insertText = String.valueOf(c);
                   // Next I insert the string into the DOM as a text node.

            }
        });


        DOM.sinkEvents(documentElement, Event.ONKEYDOWN);

I need to ensure that the value of insertText corresponds to what the user expects to be inserted when they hit the keyboard or use an IME input editor to input japanese chars.

Thanks!

No correct solution

OTHER TIPS

KeyDown and KeyUp are about the keys depressed on the keyboard. If you're interested in more high-level events that results from these keys (and possibly combine them, e.g. Shift and A produces an uppercase A) then listen to the KeyPress events.

Try with KeyCodeEvent#getNativeKeyCode() to get the native key code. These key codes are enumerated in the KeyCodes class.

char ch = (char)keyDownEvent.getNativeKeyCode()

Please have a look at post Mnemonics in GWT that is asked in the same context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top