What does wxWidgets "EVT_CHAR_HOOK" do?

I support the wxWidgets C ++ application, which 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 assume that it intercepts key events in some way, which takes precedence over β€œstandard” key events. One of the annoying things I just discovered is that if this hook is set, any accelerator keys that could be defined will no longer fire their events, even if the event handler calls Skip () on the event. I also saw some google search messages that seemed to suggest that EVT_CHAR_HOOK might not be supported on all platforms. Is this true and should I use it?

+4
source share
1 answer

I just looked at src/gtk/window.cpp and found this snippet:

  // 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 the OnCharHook event OnCharHook ?

According to one of the wx mailing list messages:

If you want the frame to catch all char events, use EVT_CHAR_HOOK, otherwise events will be sent to children. If you want to catch things like escape, you need to set the wxWANTS_CHARS flag to the frame. Also, make sure you call event.Skip () for characters that you are not processing.

But another post:

... do not use EVT_CHAR_HOOK (), it is a hack. In addition, this is a hacked Windows file and I personally am not at all interested in getting it to work correctly. If anything, I would like to give it up and completely get rid of it. Vz.

This post may interest you .

+3
source

All Articles