You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my first attempt at trying to catch keys, I think I found a bug. The first time I ran it, I had success catching the Tab key, which only popped up a message box to show the code worked. So, I got greedy and tried to catch both the Alt and the Ctrl keys. Here's what that code looked like: Bind(wxEVT_CHAR_HOOK, &MyFrame::OnChar, this);
void MyFrame::OnChar(wxKeyEvent &event){ switch ( event.GetKeyCode() ) { case WXK_TAB: wxMessageBox("Tab key");break; case WXK_ALT: wxMessageBox("Alt key");break; case WXK_CONTROL: wxMessageBox("Ctrl key");break; } }
Without being too long-winded, hitting either the Alt key or Ctrl key made the switch statement loop through their respective wxMessageBoxes() 4 times. Without fail.
Linux Mint 21.3
wxWidgets-3.2.4
The text was updated successfully, but these errors were encountered:
Please provide a way of reproducing the problem in a sample. With this diff:
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 5f32257c6b..751de45266 100644
--- a/samples/minimal/minimal.cpp+++ b/samples/minimal/minimal.cpp@@ -175,6 +175,11 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
++ auto p = new wxPanel(this);+ p->Bind(wxEVT_CHAR_HOOK, [](wxKeyEvent& event) {+ wxLogMessage("Char hook: %d", event.GetKeyCode());+ });
}
I don't see anything wrong, i.e. pressing either Alt or Ctrl results in just one message, as expected.
Also note that you should call event.Skip() for this event in your event handler unless you really want to prevent the default handling from taking place.
Sorry, but I have no way of knowing it if your example code doesn't show it.
The code i showed you used wxMessageBox(), not wxLogMessage.
Needless to say, I don't see the bug with the same diff using wxMessageBox() neither. You could have tried it yourself.
I'm just trying to help you guys.
Thank you, but what really helps is following our bug reporting guidelines, and notably providing a complete self-contained example reproducing the problem. Could you please make one as explained there?
In my first attempt at trying to catch keys, I think I found a bug. The first time I ran it, I had success catching the Tab key, which only popped up a message box to show the code worked. So, I got greedy and tried to catch both the Alt and the Ctrl keys. Here's what that code looked like:
Bind(wxEVT_CHAR_HOOK, &MyFrame::OnChar, this);
void MyFrame::OnChar(wxKeyEvent &event){
switch ( event.GetKeyCode() ) { case WXK_TAB: wxMessageBox("Tab key");break; case WXK_ALT: wxMessageBox("Alt key");break; case WXK_CONTROL: wxMessageBox("Ctrl key");break; } }
Without being too long-winded, hitting either the Alt key or Ctrl key made the switch statement loop through their respective wxMessageBoxes() 4 times. Without fail.
Linux Mint 21.3
wxWidgets-3.2.4
The text was updated successfully, but these errors were encountered: