VST, Windows 8, Ableton.
After my plugin grabs keyboard focus (by either opening a save/load dialog, or a combobox popupmenu) if I press a QWERTY key the program freezes. It's getting stuck in one of the for loops of the handleKeyPress method:
bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter) { updateCurrentModifiers(); bool keyWasUsed = false; const KeyPress keyInfo (keyCode, ModifierKeys::getCurrentModifiers().withoutMouseButtons(), textCharacter); for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) { const WeakReference<Component> deletionChecker (target); if (const Array <KeyListener*>* const keyListeners = target->keyListeners) { for (int i = keyListeners->size(); --i >= 0;) { keyWasUsed = keyListeners->getUnchecked(i)->keyPressed (keyInfo, target); if (keyWasUsed || deletionChecker == nullptr) return keyWasUsed; i = jmin (i, keyListeners->size()); } } keyWasUsed = target->keyPressed (keyInfo); if (keyWasUsed || deletionChecker == nullptr) break; if (Component* const currentlyFocused = Component::getCurrentlyFocusedComponent()) { const bool isTab = (keyInfo == KeyPress::tabKey); const bool isShiftTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier, 0)); if (isTab || isShiftTab) { currentlyFocused->moveKeyboardFocusToSibling (isTab); keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent()); if (keyWasUsed || deletionChecker == nullptr) break; } } } return keyWasUsed; }
The trapping for loop is:
for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent())
The target->keyPressed call that occurs halfway through the method isn't implemented in any of my components, so they're always returning false. So as a workaround I've been implementing keyPressed in all of my relevant components and having them return true, which in turn breaks the for loop. While this works, I feel like I'm plugging holes in a leaky boat, when I should be trying to stop the cause of the leaks in the first place (weak metaphor?). Any suggestions?