Mac modifier key bug fix improvement?

I have a situation where I’m trying to use the shift key to trigger a command where the user may potentially be holding some other keys to play notes on a MidiKeyboardComponent. The issue I was having was that NSViewComponentPeer::redirectModKeyChange clears all of the currently held keys before applying the modifier changes on Mac. According to this old thread:, the currently down keys were cleared to prevent a bug where the key up for those keys was never registered if the command key were pressed while holding a key.

I can confirm that is the case and that the change added in that thread fixed that case. But the sticking keys don’t seem to be an issue with any other modifier. What I’m using now and what I propose as an improvement would be to conditionally clear the keysCurrentlyDown ONLY when the command modifier is pressed:

source -

void redirectModKeyChange (NSEvent* ev)
// (need to retain this in case a modal loop runs and our event object gets lost)
const std::unique_ptr<NSEvent, NSObjectDeleter> r ([ev retain]);

    // Proposed: only clear the keysCurrentlyDown when the Command key is pressed
    if (([ev modifierFlags] & NSEventModifierFlagCommand) != 0)
        handleKeyUpOrDown (true);

    updateModifiers (ev);