Beeping while selecting text in a wxTextCtrl control Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Quentin
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Jul 07, 2010 9:47 am

Beeping while selecting text in a wxTextCtrl control

Post by Quentin » Sat Oct 02, 2010 8:15 pm

Hi,

I wrote a wxEVT_KEY_DOWN event handler for the wxTextCtrl control. The handler checks whether user pressed Ctrl+A and if he did - it selects the whole text in the wxTextCtrl.

Here's my handler:

Code: Select all

void MyProgFrame::OnButtonPress(wxKeyEvent& event)
{
    if( (event.GetModifiers() == wxMOD_CONTROL) && (event.GetUnicodeKey() == wxT('A')) )
    {
        TextCtrl1->SetSelection(-1, -1);
    }

    event.Skip();
}
The only thing which annoys me is the beeping while pressing the above combination.

I read about accelerators. According to docs:
For example, you can use an accelerator table to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning 'OK'
So I added this code to my program:

Code: Select all

wxAcceleratorEntry entry(wxACCEL_CTRL, (int)'A', ID_TEXTCTRL1);

wxAcceleratorTable table(1, &entry);

SetAcceleratorTable(table);
and yes - the beeping doesn't occur any more. But now, my handler isn't being called when I press Ctrl+A :lol:

Do you know why is that :?: Accelerators aren't well described in the documentation...
Image

eranif
Moderator
Moderator
Posts: 607
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif » Sun Oct 03, 2010 6:30 am

to avoid the beep, avoid calling even.Skip() if the condition matches, so your code should look like this now:

Code: Select all

void MyProgFrame::OnButtonPress(wxKeyEvent& event)
{
    if( (event.GetModifiers() == wxMOD_CONTROL) && (event.GetUnicodeKey() == wxT('A')) )
    {
        TextCtrl1->SetSelection(-1, -1);
        return;
    }

    event.Skip();
}
Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org

Post Reply