Page 1 of 1

Beeping while selecting text in a wxTextCtrl control

Posted: Sat Oct 02, 2010 8:15 pm
by Quentin
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...

Posted: Sun Oct 03, 2010 6:30 am
by eranif
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