You don't need to trigger any events to call your own function -- just call it directly instead. Calling the event handler directly is awkward and not recommended, but this is a trivial solution avoiding it -- just have a normal function that you can call both from that event handler and directly:
void Sample::OnTextCharEvnt(wxCommandEvent& event) { DoHandleCharEvent(event.GetUnicodeKey()); }
void Sample::DoHandleCharEvent(wchar_t key) { ... your actual code for handling it ... }
void Sample::SomeOtherFunction() { DoHandleEnter(); }
If you used the recommended Bind()
function rather than old Connect()
, you could even avoid having the trivial OnTextCharEvnt()
entirely by using a lambda instead, e.g.:
FTextCtrl->Bind(wxEVT_CHAR, [](wxCommandEvent& event) {
DoHandleCharEvent(event.GetUnicodeKey());
});
All this ignores the fact that you should not be using wxEVT_CHAR
with wxTextCtrl
in the first place, but should handle either wxEVT_TEXT
or wxEVT_TEXT_ENTER
or both of them, instead of lower level char events (that won't get triggered at all if the user pastes something in the control, for example).