How do I convert the javascript code "window.onkeyup" (or o开发者_如何学编程nkeyup in body tag) to GWT?
Regards
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
}
}
});
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_thread/thread/6072c87aa27a2d6e/524334b959683f77
精彩评论