开发者

Check that KeyUpEvent is a space in GWT

开发者 https://www.devze.com 2023-01-31 01:30 出处:网络
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 character

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 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号