tags:

views:

335

answers:

2

Hi,

How do I convert the javascript code "window.onkeyup" (or onkeyup in body tag) to GWT?

Regards

A: 

I think you could do that with KeyboardListener.

There is a good discussion thread about it (and some issues): http://groups.google.com/group/google-web-toolkit/browse%5Fthread/thread/6072c87aa27a2d6e/524334b959683f77

Petteri Hietavirta
but that is not for body.onkeyup :(
also listeners are deprecated in favor of handlers since GWT 1.6
Matt Moriarity
+3  A: 

For a page wide listener, you want to take a look at Event.addNativePreviewHandler. Attaching a keyup listener there should give you the effect you want. Modifing the snippet here should get you started:

Event.addNativePreviewHandler(new NativePreviewHandler() {
  public void onPreviewNativeEvent(final NativePreviewEvent event) {
    final int eventType = event.getTypeInt();
    switch (eventType) {
      case Event.ONKEYUP:
        //magic here
        break;
      default:
        // not interested in other events
    }
  }
});
bikesandcode