检查 GWT 中的 KeyUpEvent 是否为空格

发布于 2024-10-08 12:28:50 字数 126 浏览 0 评论 0原文

我从教程中注意到,通常通过将 getNativeKeyCode 与 KeyCodes 进行比较来检查 KeyUpEvent 事件。但 KeyCodes 只有特殊键的常量,没有字符。有没有办法绕过对空格键的值进行硬编码(看起来是“32”)?

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")?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…红帽 2024-10-15 12:28:51

我编写此代码来通过检查空格键(32)来关闭弹出面板,它对我有用

   @Override
    protected void onPreviewNativeEvent(NativePreviewEvent event) {
        super.onPreviewNativeEvent(event);
        if(event.getNativeEvent().getKeyCode() == 32){ // spacebar
            hide();
        }   
    }

KeyUpEvent 也有 getNativeEvent();

你可以用同样的方式检查

KeyUpEvent k;
k.getNativeEvent().getKeyCode() == 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 
一个人练习一个人 2024-10-15 12:28:51

您可以仅使用字符作为空格进行比较,如下所示:

if(event.getNativeKeyCode() == ' ') {
   // special logic here 
}

You can just use the char for space to compare against, like this:

if(event.getNativeKeyCode() == ' ') {
   // special logic here 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文