Check that KeyUpEvent is a space in GWT
Question
I notice from the tutorial that normally KeyUpEvent event is checked by comparing getNativeKeyCode with 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")?
Solution
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
OTHER TIPS
You can just use the char for space to compare against, like this:
if(event.getNativeKeyCode() == ' ') {
// special logic here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow