From 3fa942795ea10d26388335aeda841fa1c3e9e8e2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 21 Jun 2020 01:13:55 +0200 Subject: [PATCH] Avoid annoying beep when using Alt-Backspace in MSW text controls Although the native (single line) text control understands Alt-Backspace as an accelerator for "Undo", using it was not really practical because it resulted in an annoying beep due to Alt-anything trying to find an item with matching mnemonic in the menu. Work around this native (mis)feature by pretending to handle this particular Alt-combination ourselves when the currently focused control is text-like, as indicated by it overriding WXGetTextEntry() -- this is not ideal, but seems to be the best we can currently do. An alternative could be to just mark Alt-Backspace as handled unconditionally. --- src/msw/toplevel.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 4c552f2604..aeabf46f43 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -290,6 +290,22 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX DoRestoreLastFocus(); } + else if ( id == SC_KEYMENU ) + { + // Alt-Backspace is understood as an accelerator for "Undo" + // by the native EDIT control, but pressing it results in a + // beep by default when the resulting SC_KEYMENU is handled + // by DefWindowProc(), so pretend to handle it ourselves if + // we're editing a text control to avoid the annoying beep. + if ( lParam == VK_BACK ) + { + if ( wxWindow* const focus = FindFocus() ) + { + if ( focus->WXGetTextEntry() ) + processed = true; + } + } + } #ifndef __WXUNIVERSAL__ // We need to generate events for the custom items added to the