开发者

GWT: Wrong Key Codes generated with a French keyboard [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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 ?


It seems it's not a GWT-specific bug - please see Issue 3753 and all the references there for a comprehensive view of the problem. Basically, there's a huge mess with how different browsers handle key events - the GWT Team seems to be working on fixing that and a comprehensive fix should be included with GWT 2.1 (whenever is comes out - in the meantime, it might be worth checking out the status of the issue and try the SVN version).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜