GWT: Wrong Key Codes generated with a French keyboard

Posted by Flueras Bogdan on Stack Overflow See other posts from Stack Overflow or by Flueras Bogdan
Published on 2010-04-27T08:18:24Z Indexed on 2010/04/27 11:43 UTC
Read the original article Hit count: 439

Filed under:
|
|

On any french keyboard(AZERTY) the dot char '.' is generated with (Shift + ;) combination while the percent char '%' is generated with (Shift + ù) combination

So when I type one of the above combinations in a GWT text area to write '.' or ' %', the key codes generated for these events are KEY_DELETE in the former case and KEY_LEFT in the latter.

TextArea txtArea = new TextArea();
txtArea.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {                
                switch (charCode) {
                    case KeyCodes.KEY_LEFT: { // key code 37
                        System.out.write("KEY LEFT");    
                        break;
                    }
                    case KeyCodes.KEY_DELETE: {   // key code 46                   
                         System.out.write("DELETE");
                         break;
                    }
                }

Workaround: get charCode and do a character match:

charCode = event.getCharCode();
if (charCode == '.') {...}
else if (charCode == '%') {...} 

Is this a GWT bug? And is there a more elegant way to handle this ?

© Stack Overflow or respective owner

Related posts about gwt

Related posts about keyboard