diff --git a/src/KeyboardCapture.cpp b/src/KeyboardCapture.cpp index e69410056..77b68e693 100644 --- a/src/KeyboardCapture.cpp +++ b/src/KeyboardCapture.cpp @@ -190,6 +190,26 @@ public: if ( !( sPreFilter() && sPreFilter()( key ) ) ) return Event_Skip; +#ifdef __WXMAC__ + // Bug 2107 (Mac only) + // wxButton::SetDefault() alone doesn't cause correct event routing + // of key-down to the button when a text entry or combo has focus, + // but we can intercept wxEVT_CHAR_HOOK here and do it + if ( type == wxEVT_CHAR_HOOK && + key.GetKeyCode() == WXK_RETURN ) { + if (auto top = + dynamic_cast< wxTopLevelWindow* >( + wxGetTopLevelParent( wxWindow::FindFocus() ) ) ) { + if ( auto button = + dynamic_cast( top->GetDefaultItem() ) ) { + wxCommandEvent newEvent{ wxEVT_BUTTON, button->GetId() }; + button->GetEventHandler()->AddPendingEvent( newEvent ); + return Event_Processed; + } + } + } +#endif + // Make a copy of the event and (possibly) make it look like a key down // event. if (type == wxEVT_CHAR_HOOK)