Pages

Saturday, 25 February 2012

GWT KeyPressHandler doesn't work for your widget? Use KeyDownHandler instead.

If you want to catch the 'Enter' or 'Escape' key press event on your GWT widget (FocusPanel, TextBox, ...) and have tried the KeyPressHandler but not success, try to switch to the KeyDownHandler


outer.addKeyDownHandler(new KeyDownHandler() {     
  public void onKeyDown(KeyDownEvent event) {
    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
      loginButton.click();
    } else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
    cancelButton.click();
    }
  }
});

No comments:

Post a Comment