3

Hey, I'm running GWT on ubuntu and trying to learn by following the tutorial guide found on Google . I have some problem with making a textfield register when user hit the enter button. It works with specificing arbitrary character, so I don't think it is any problem with the code. So it probably is that KeyCodes.KEY_ENTER isn't supported in linux? What else can I write instead to make it read when user hit enter?

    newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
      public void onKeyPress(KeyPressEvent event) {
        if (event.getCharCode() == KeyCodes.KEY_ENTER) {
          addStock();
          System.out.println("Foo");
        }
      }
    });
starcorn
  • 8,261
  • 23
  • 83
  • 124
  • Possible duplicate of http://stackoverflow.com/questions/4115770/keypressevent-getcharcode-returning-0-for-all-special-keys-like-enter-tab-es – Attila Jul 17 '13 at 01:38

2 Answers2

5

Use the getKeyCode() method that you'll find on the native event.

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER)
  System.out.println("Foo");
Mia Clarke
  • 8,134
  • 3
  • 49
  • 62
1

If you think that KeyCodes.KEY_ENTER isn't supported in linux you can just replace it by:

event.getCharCode() == 13
Jla
  • 11,304
  • 14
  • 61
  • 84