GWT (event.getCharCode) behaves differently in IE and Firefox

流过昼夜 提交于 2019-12-12 11:53:05

问题


I was going through the tutorial available on GWT website for StockWatcher application and testing the application as described in Step4: Manage Events on the Client.

Below piece of code behaves differently in Firefox and IE7. In IE7 this works well, i.e. If I enter some junk characters in Text field and hit Enter "event.getCharCode() == KeyCodes.KEY_ENTER" line gets executed successfully and I could see an alert message. However this same line does not work, if I use Firefox.

When I use Firefox and press Enter, event.getCharCode returns some junk character. What am I doing wrong here? or is this expected behavior?

newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              addStock();
            }
          }
        });

回答1:


Use a KeyUpHandler instead of a KeyPressHandler to catch non-character keys (like enter, escape, etc.). Call KeyUpEvent#getNativeKeyCode() to get the key code.



来源:https://stackoverflow.com/questions/5569803/gwt-event-getcharcode-behaves-differently-in-ie-and-firefox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!