What does wxWidgets' EVT_CHAR_HOOK do?

无人久伴 提交于 2020-01-02 06:07:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3876966/what-does-wxwidgets-evt-char-hook-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!