wxSlider Processing Problem With wxKeyEvent (ding)
Posted: Fri Jan 29, 2010 4:29 pm
I have a custom control, a wxBitmapSlider derived from wxSlider. It allows an optional custom bitmap for the slider and thumb.
I have key down and key up events attached to this control.
The events work fine, but every time I press a key I get an annoying "ding" from Windows. Probably because a slider doesn't natively understand keyboard events.
I've tried a few things to try to get rid of this, but nothing has worked.
The handlers are:
I've tried both 'true' and 'false' in event.Skip() and it hasn't mattered.
In this custom wxBitmapSlider control, I'm trying to prevent keyboard focus in the first place, but this doesn't seem to have any effect:
I've also tried catching key down/up events within the custom control and propagating/skipping them there to no avail. The events work, and I still get that stupid ding.
Here's an earlier version of the sort of app I'm working on so you get the idea of what I'm trying to do:
What I'm trying to accomplish is allowing someone to move one of the two sliders on the left (pitch and modulation controls) while still being able to use the letter keys to control what notes are playing.
Since the slider gets focus when someone clicks it, I have to be able to process keys, or prevent focus, or automatically move focus back to another control. None of the other controls on the dialog are a problem, but the slider is, and I suspect it's because sliders don't natively handle key events.
Any suggestions?
I have key down and key up events attached to this control.
Code: Select all
_modWheel = new wxBitmapSlider( itemDialog1, ID_MODWHEEL, 0, 0, 16383, wxDefaultPosition, wxSize( 30, 108 ), wxSL_VERTICAL|wxSL_INVERSE );
_modWheel->Connect(ID_MODWHEEL, wxEVT_KEY_DOWN, wxKeyEventHandler(wxKeyboard::OnKeyDown), NULL, this);
_modWheel->Connect(ID_MODWHEEL, wxEVT_KEY_UP, wxKeyEventHandler(wxKeyboard::OnKeyUp), NULL, this);
I've tried a few things to try to get rid of this, but nothing has worked.
The handlers are:
Code: Select all
void wxKeyboard::OnKeyDown( wxKeyEvent& event )
{
int key = event.GetKeyCode();
if( key == WXK_TAB )
{
return;
}
int note = GetNoteValue( key );
if( note == 0 )
{
event.Skip(true);
return;
}
// Only play if the note is not already playing -- prevents retriggers.
if( !_playing[note] )
{
_releasing[note] = false;
PlayNote( note );
}
event.Skip(true);
}
void wxKeyboard::OnKeyUp( wxKeyEvent& event )
{
int key = event.GetKeyCode();
int note = GetNoteValue( key );
if( note == 0 )
{
event.Skip(true);
return;
}
StopNote( note );
event.Skip(true);
}
In this custom wxBitmapSlider control, I'm trying to prevent keyboard focus in the first place, but this doesn't seem to have any effect:
Code: Select all
virtual bool AcceptsFocusFromKeyboard() const { return false; }
virtual bool AcceptsFocus() const { return false; }
Here's an earlier version of the sort of app I'm working on so you get the idea of what I'm trying to do:
What I'm trying to accomplish is allowing someone to move one of the two sliders on the left (pitch and modulation controls) while still being able to use the letter keys to control what notes are playing.
Since the slider gets focus when someone clicks it, I have to be able to process keys, or prevent focus, or automatically move focus back to another control. None of the other controls on the dialog are a problem, but the slider is, and I suspect it's because sliders don't natively handle key events.
Any suggestions?