void wxButton::OnCharHook(wxKeyEvent& event) { // We want to ensure that the button always processes Enter key events // itself, even if it's inside some control that normally takes over them // (this happens when the button is part of an in-place editor control for // example). if ( event.GetKeyCode() == WXK_RETURN ) { // We should ensure that subsequent key events are still generated even // if we did handle EVT_CHAR_HOOK (normally this would suppress their // generation). event.DoAllowNextEvent(); } else { event.Skip(); } }
void OnCharHook( wxKeyEvent& aEvent ) { // On certain platforms, EVT_CHAR_HOOK is the only handler that receives // certain "special" keys. However, it doesn't always receive "normal" // keys correctly. For example, with a US keyboard, it sees ? as shift+/. // // Untangling these incorrect keys would be too much trouble, so we bind // both events, and simply skip the EVT_CHAR_HOOK if it receives a // "normal" key. const enum wxKeyCode skipped_keys[] = { WXK_NONE, WXK_SHIFT, WXK_ALT, WXK_CONTROL, WXK_CAPITAL, WXK_NUMLOCK, WXK_SCROLL, WXK_RAW_CONTROL }; int key = aEvent.GetKeyCode(); for( size_t i = 0; i < sizeof( skipped_keys ) / sizeof( skipped_keys[0] ); ++i ) { if( key == skipped_keys[i] ) return; } if( key <= 255 && isprint( key ) && !isspace( key ) ) { // Let EVT_CHAR handle this one aEvent.DoAllowNextEvent(); // On Windows, wxEvent::Skip must NOT be called. // On Linux and OSX, wxEvent::Skip MUST be called. // No, I don't know why. #ifndef __WXMSW__ aEvent.Skip(); #endif } else { OnChar( aEvent ); } }
void FrequencyDialog::OnChar(wxKeyEvent& event) { int c = event.GetKeyCode(); long long freq; std::string lastDemodType = activeDemod?activeDemod->getDemodulatorType():wxGetApp().getDemodMgr().getLastDemodulatorType(); switch (c) { case WXK_RETURN: case WXK_NUMPAD_ENTER: // Do Stuff freq = strToFrequency(dialogText->GetValue().ToStdString()); if (targetMode == FDIALOG_TARGET_DEFAULT) { if (activeDemod) { activeDemod->setTracking(true); activeDemod->setFollow(true); activeDemod->setFrequency(freq); activeDemod->updateLabel(freq); } else { wxGetApp().setFrequency(freq); } } if (targetMode == FDIALOG_TARGET_BANDWIDTH) { if (lastDemodType == "USB" || lastDemodType == "LSB") { freq *= 2; } if (activeDemod) { activeDemod->setBandwidth(freq); } else { wxGetApp().getDemodMgr().setLastBandwidth(freq); } } Close(); break; case WXK_ESCAPE: Close(); break; } std::string allowed("0123456789.MKGHZmkghz"); if (allowed.find_first_of(c) != std::string::npos || c == WXK_DELETE || c == WXK_BACK || c == WXK_NUMPAD_DECIMAL || (c >= WXK_NUMPAD0 && c <= WXK_NUMPAD9)) { #ifdef __linux__ dialogText->OnChar(event); event.Skip(); #else event.DoAllowNextEvent(); #endif } else if (event.ControlDown() && c == 'V') { // Alter clipboard contents to remove unwanted chars wxTheClipboard->Open(); wxTextDataObject data; wxTheClipboard->GetData(data); std::string clipText = data.GetText().ToStdString(); std::string pasteText = filterChars(clipText, std::string(allowed)); wxTheClipboard->SetData(new wxTextDataObject(pasteText)); wxTheClipboard->Close(); event.Skip(); } else if (c == WXK_RIGHT || c == WXK_LEFT || event.ControlDown()) { event.Skip(); } }