Check that KeyUpEvent is a space in GWT
I notice from the tutorial that normally KeyUpEvent event is checked by comparing getNativeKeyCode w开发者_C百科ith KeyCodes. But KeyCodes only has constants for special keys and none of the characters. Is there a way to get around hard-coding the value for spacebar (which appears to be "32")?
I write this code to close the popup panel with checking spacebar (32) and it works for me
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
super.onPreviewNativeEvent(event);
if(event.getNativeEvent().getKeyCode() == 32){ // spacebar
hide();
}
}
KeyUpEvent also has getNativeEvent();
that you can check with the same way
KeyUpEvent k;
k.getNativeEvent().getKeyCode() == 32
You can just use the char for space to compare against, like this:
if(event.getNativeKeyCode() == ' ') {
// special logic here
}
精彩评论