Handling Ctrl+Tab


#1

Hi Jules,

I noticed that ComponentPeer::HandleKeyPress returns unconditionally on Tab press.
Whether the following code should check for keyWasUsed flag before breaking the call chain?

// @file: juce_ComponentPeer.cpp

bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter)
{
	...
    ...
	for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent())
    {
		...
		...
		
		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());
                break; // We should break only if keyWasUsed is set.
            }
        }
    }

    return keyWasUsed;
}

#2

yes… I think that makes sense…

Your question seems a little strange though, because your title is “handling ctrl+tab”, but this code should never be executed for ctrl+tab?


#3

Thanks for your reply.

I am trying to handle Ctrl+Tab using Application Command Target. Control reaches handleKeyPress, then returns due to above mentioned condition. Am I missing something here?
If the purpose of that piece of code is just to handle tab order, then, there should be a check to make sure no other modifier key is down (except shift).


#4

There IS a check - look at the code above! It specifically checks for only tab or shift+tab, which is why I don’t understand how you’d have ended up in there.


#5

Hi Jules,

I rebuilt my juce dll and every thing worked fine. :oops:

For some reason I was not able to step into KeyPress.cpp and thought of rebuilding dll.