wxWidgets 是什么意思? EVT_CHAR_HOOK做什么?

发布于 2024-09-26 02:01:31 字数 243 浏览 1 评论 0原文

我正在维护一个 wxWidgets C++ 应用程序,它使用 EVT_CHAR_HOOK 来捕获高级窗口中的关键事件。我找不到此事件的任何真实文档,但我可以推测它以某种优先于“标准”关键事件的方式拦截关键事件。我刚刚发现的一件令人不安的事情是,如果这个挂钩到位,任何可能已定义的加速键将不再触发其事件,即使事件处理程序在事件上调用 Skip() 也是如此。我在谷歌搜索时也看到了一些帖子,似乎表明并非所有平台都支持 EVT_CHAR_HOOK。这是真的吗?我应该使用它吗?

I am maintaining a wxWidgets C++ application that uses EVT_CHAR_HOOK to capture key events in a high level window. I can't find any real documentation for this event but I can surmise that it intercepts key events in some way that has priority over the "standard" key events. One disturbing thing that I just discovered is that, if this hook is in place, any accelerator keys that might have been defined will no longer fire their events even if the event handler calls Skip() on the event. I've also seen some posts when searching on google that seemed to suggest that EVT_CHAR_HOOK may not be supported on all platforms. Is this true and should I be using it?

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

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

发布评论

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

评论(1

栖竹 2024-10-03 02:01:31

我刚刚查看了 src/gtk/window.cpp 并找到了这篇文章:

        // Implement OnCharHook by checking ancestor top level windows
        wxWindow *parent = win;
        while (parent && !parent->IsTopLevel())
            parent = parent->GetParent();
        if (parent)
        {
            event.SetEventType( wxEVT_CHAR_HOOK );
            ret = parent->HandleWindowEvent( event );
        }

        if (!ret)
        {
            event.SetEventType(wxEVT_CHAR);
            ret = win->HandleWindowEvent( event );
        }

所以,也许您只需要从 OnCharHook 事件中返回 false处理程序?

根据 wx 邮件列表帖子之一:

如果您希望框架捕获所有 char 事件,请使用 EVT_CHAR_HOOK,否则事件将发送给子级。如果你想捕获像逃逸这样的东西,你需要在框架上设置 wxWANTS_CHARS 标志。另外,请确保对不处理的字符调用 event.Skip() 。

但另一篇文章指出:

...不要使用 EVT_CHAR_HOOK(),它是一种 hack。此外,它是一个特定于 Windows 的 hack
我个人对让它正常工作一点也不感兴趣。如果有的话,
我想弃用它并完全摆脱它。 VZ。

此帖子可能是您感兴趣

I just looked into src/gtk/window.cpp and found this piece:

        // Implement OnCharHook by checking ancestor top level windows
        wxWindow *parent = win;
        while (parent && !parent->IsTopLevel())
            parent = parent->GetParent();
        if (parent)
        {
            event.SetEventType( wxEVT_CHAR_HOOK );
            ret = parent->HandleWindowEvent( event );
        }

        if (!ret)
        {
            event.SetEventType(wxEVT_CHAR);
            ret = win->HandleWindowEvent( event );
        }

So, maybe you just need to return false from your OnCharHook event handler?

In accordance to one of wx Mailing list post:

If you want the frame to catch all char events, use EVT_CHAR_HOOK, otherwise the events get sent to the children. If you want to catch stuff like escape, you need to set wxWANTS_CHARS flag on the frame. Also, make sure you call event.Skip() on chars you don't process.

But another post states:

...don't use EVT_CHAR_HOOK(), it is a hack. Moreover, it is a Windows-specific hack and
I'm personally not at all interested in getting it to work right. If anything,
I'd like to deprecate it and get rid of it completely. VZ.

This post may be of interest to you.

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