{ m_logText->AppendText("Test accelerator \"Esc\" used.\n"); }
void OnClear(wxCommandEvent& WXUNUSED(event)) { m_logText->Clear(); }
- void OnSkip(wxCommandEvent& event) { m_skip = event.IsChecked(); }
+ void OnSkipDown(wxCommandEvent& event) { m_skipDown = event.IsChecked(); }
+ void OnSkipHook(wxCommandEvent& event) { m_skipHook = event.IsChecked(); }
- void OnKeyDown(wxKeyEvent& event) { LogEvent("KeyDown", event); }
+ void OnKeyDown(wxKeyEvent& event)
+ {
+ LogEvent("KeyDown", event);
+ if ( m_skipDown )
+ event.Skip();
+ }
void OnKeyUp(wxKeyEvent& event) { LogEvent("KeyUp", event); }
void OnChar(wxKeyEvent& event) { LogEvent("Char", event); }
+ void OnCharHook(wxKeyEvent& event)
+ {
+ LogEvent("Hook", event);
+ if ( m_skipHook )
+ event.Skip();
+ }
+
void OnPaintInputWin(wxPaintEvent& event);
void LogEvent(const wxString& name, wxKeyEvent& event);
wxTextCtrl *m_logText;
wxWindow *m_inputWin;
- bool m_skip;
+ bool m_skipHook,
+ m_skipDown;
};
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title),
m_inputWin(NULL),
- m_skip(true)
+ m_skipHook(true),
+ m_skipDown(true)
{
SetIcon(wxICON(sample));
{
QuitID = wxID_EXIT,
ClearID = wxID_CLEAR,
- SkipID = 100,
+ SkipHook = 100,
+ SkipDown,
TestAccelA,
TestAccelCtrlA,
TestAccelEsc
menuFile->Append(TestAccelEsc, "Test accelerator &3\tEsc");
menuFile->AppendSeparator();
- menuFile->AppendCheckItem(SkipID, "Call event.&Skip()\tCtrl-S");
- menuFile->Check(SkipID, true);
+ menuFile->AppendCheckItem(SkipHook, "Skip CHAR_HOOK event",
+ "Not skipping this event disables both KEY_DOWN and CHAR events"
+ );
+ menuFile->Check(SkipHook, true);
+ menuFile->AppendCheckItem(SkipDown, "Skip KEY_DOWN event",
+ "Not skipping this event disables CHAR event generation"
+ );
+ menuFile->Check(SkipDown, true);
menuFile->AppendSeparator();
menuFile->Append(QuitID, "E&xit\tAlt-X", "Quit this program");
Connect(ClearID, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(MyFrame::OnClear));
- Connect(SkipID, wxEVT_COMMAND_MENU_SELECTED,
- wxCommandEventHandler(MyFrame::OnSkip));
+ Connect(SkipHook, wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(MyFrame::OnSkipHook));
+ Connect(SkipDown, wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(MyFrame::OnSkipDown));
Connect(TestAccelA, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(MyFrame::OnTestAccelA));
wxPaintEventHandler(MyFrame::OnPaintInputWin),
NULL, this);
+ // notice that we don't connect OnCharHook() to the input window, unlike
+ // the usual key events this one is propagated upwards
+ Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(MyFrame::OnCharHook));
+
+ // status bar is useful for showing the menu items help strings
+ CreateStatusBar();
+
// and show itself (the frames, unlike simple controls, are not shown when
// created initially)
Show(true);
);
m_logText->AppendText(msg);
-
- if ( m_skip )
- event.Skip();
}
{
wxKeyEvent wxevent(wxEVT_KEY_DOWN);
SetupKeyEvent( wxevent, event );
+
+ // Generate wxEVT_CHAR_HOOK before sending any other events but only when
+ // the key is pressed, not when it's released (the type of wxevent is
+ // changed by SetupKeyEvent() so it can be wxEVT_KEY_UP too by now).
+ if ( wxevent.GetEventType() == wxEVT_KEY_DOWN )
+ {
+ wxKeyEvent eventHook(wxevent);
+ eventHook.SetEventType(wxEVT_CHAR_HOOK);
+ if ( wxGetTopLevelParent(GetWXPeer())->OSXHandleKeyEvent(eventHook) )
+ return true;
+ }
+
bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
// this will fire higher level events, like insertText, to help