Hanging keys when pressing modifier-key: bugfix?


#1

Okay, here a pretty specific situation:

-Press and hold a key (for instance s), a KeystateChanged callback will be made.
-Now press and hold cmd (a ModifierKeysChanged callback will be made)
-If you now release the s, no keyup will be registered, unless the s is pressed again.

What would seem logical to me is that all keys down are cleared when pressing a modifier key. At least, this solves the problems this behavoir causes in our App. If the cmd + s shortcut is made in the normal sequence (first cmd, then s), all goes well.

It modified the juce_mac_NSViewComponentPeer.mm file a bit:


void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
{
    // first clear all keys down
    keysCurrentlyDown.clear();

   // now handle callbacks
   handleKeyUpOrDown();

    // proceed as usual (original code)
    updateModifiers (ev);
    handleModifierKeysChange();
}

Does this seem like the way to go, or is there perhaps a more elegant solution?

Cheers,

Tim


#2

Thanks, that seems like a good idea.

The only problem might be if you’ve got a key + modifier held down and you release the modifier, so how about this:

if ([ev type] == NSKeyDown) { keysCurrentlyDown.clear(); handleKeyUpOrDown(); }


#3

I see what you mean, when you (for instance) press cmd -> s, and then let go of the cmd, the ‘s’ would get cleared, right? The problem now is that the event passed in to redirectModKeyChange never is of type NSKeyDown, but allways is NSFlagsChanged. So, the if statement doesn’t have much effect.

I’m guessing this is pretty hard coded, NSEvents is OS-X stuff right?


#4

Hmm, yes, that’s tricky then. I can’t think of a better workaround, so will go with your idea - it’s better that keys might sometimes be released early than stuck down!


#5

okay, cool.

Glad to have been of use!