A bug in KeyPressMappingSet::keyStateChanged?

Hi jules,

It seems there is a bug in KeyPressMappingSet::keyStateChanged () as modifiers aren’t checked … (or maybe i missed something ?)

Anyway, if for example you’ve got two different commands A and B with followings mappings:
A : "a"
B: “shift+a”

Pressing “a” will trigger both commands…

I tried a temporary naive fix which obviously does the trick (see below),
but this fix should maybe spread to other method as KeyPressMappingSet::findCommandForKeyPress() or KeyPressMappingSet::containsMapping()…

If you could check this…

Thanx in advance !


bool KeyPressMappingSet::keyStateChanged (Component* originatingComponent)
{
    bool used = false;
    const uint32 now = Time::getMillisecondCounter();

    for (int i = mappings.size(); --i >= 0;)
    {
        CommandMapping* const cm =  mappings.getUnchecked(i);

        if (cm->wantsKeyUpDownCallbacks)
        {
            for (int j = cm->keypresses.size(); --j >= 0;)
            {
                const KeyPress key (cm->keypresses.getReference (j));
                const bool isDown = key.isCurrentlyDown();

                int keyPressEntryIndex = 0;
                bool wasDown = false;

                for (int k = keysDown.size(); --k >= 0;)
                {
                    if (key == keysDown.getUnchecked(k)->key 
/* MY FIX **********************/
                        && key.getModifiers().isCtrlDown() 
                             == ModifierKeys::getCurrentModifiers().isCtrlDown()
                        && key.getModifiers().isShiftDown() 
                             == ModifierKeys::getCurrentModifiers().isShiftDown()
                        && key.getModifiers().isAltDown() 
                             == ModifierKeys::getCurrentModifiers().isAltDown()
/****************************/
                      )
                    {
                        keyPressEntryIndex = k;
                        wasDown = true;
                        break;
                    }
                }

                if (isDown != wasDown)
                {
                    int millisecs = 0;

                    if (isDown)
                    {
                        KeyPressTime* const k = new KeyPressTime();
                        k->key = key;
                        k->timeWhenPressed = now;

                        keysDown.add (k);
                    }
                    else
                    {
                        const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;

                        if (now > pressTime)
                            millisecs = now - pressTime;

                        keysDown.remove (keyPressEntryIndex);
                    }

                    invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
                    used = true;
                }
            }
        }
    }

    return used;
}

Hmm - looks like the problem must really be in KeyPress::isCurrentlyDown. I’ll check it out soon…