简体   繁体   English

GWT为我的所有Web应用程序启用esc密钥

[英]GWT enable esc key for all my web application

I need to add a function when i press esc key in each panel of my web application. 当我在Web应用程序的每个面板中按esc键时,我需要添加一个功能。 Specifically when i press esc key in my web application i need to show a panel which alert if is need to exit from the web application. 具体来说,当我在Web应用程序中按Esc键时,我需要显示一个面板,该面板会提醒是否需要从Web应用程序退出。

my question is : how can do to enable esc key shortcut ? 我的问题是:如何启用esc键快捷方式?

在GWT中,通常使用NativePreviewHandler实现全局快捷方式。

Here's a snippet from a project I work on, it should give you an idea of what to do: 这是我正在研究的项目的摘录,它应该让您知道该怎么做:

public class MyDialogBox extends com.google.gwt.user.client.ui.DialogBox 
{
    @Override
    protected void onPreviewNativeEvent(Event.NativePreviewEvent event)
    {
        super.onPreviewNativeEvent(event);
        switch (event.getTypeInt())
        {
            case Event.ONKEYDOWN:
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) 
                {
                    // do stuff
                }
                break;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM