Bug with keyboard shortcuts and grabKeyboardFocus

My app has shortcuts keys for left and right arrow. I also have a component that responds to left and right arrow in it’s keyPressed() function.

In my component, if I get a left arrow I call leftComp->grabKeyboardFocus() and if it is a right arrow I call rightComp->grabKeyboardFocus()

Everything is fine if I don’t call grabKyboardFocus(), but if I do, then the global shortcut gets called, even though my component is eating the keypress.

This causes the problem:

void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent) { keyStateChanged (focusedComponent); }

It’s only a problem for shortcuts that want up and down callbacks

Ok, I think I see. That’s pretty subtle - would it help if it passed the key state callback to the component, so it could let filter up to the mapping set if it wants it, like this:

void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent) { if (focusedComponent != 0) focusedComponent->keyStateChanged(); }

Although I’ve a feeling that could lead to some recursive callbacks.[/code]

That seems to have fixed it. I haven’t seen any recursive callbacks yet, is there anything specific I should test?

No, just a feeling. If some kind of shortcut got triggered by the callback and then does something that changes the focus…