modifierKeysChanged() does not recognize right clicks

I am having trouble recognizing right clicks. In my component, I implemented:
void modifierKeysChanged(const juce::ModifierKeys& modifiers) override;

When right clicking on some button of my component the “modifierKeysChanged()” is not triggered… Why?

  • When I press a different modifier, for example “alt”, it is triggered.

  • When I keep “alt” pressed and than start right clicking, the right clicks do trigger “modifierKeysChanged()”

I was checking this this way:

void MyComponent::modifierKeysChanged(const juce::ModifierKeys& modifiers) {
    m_modKeys = modifiers;
    if (m_modKeys.isAltDown()) {
        DBG("alt is down");
    }
    if (m_modKeys.isRightButtonDown()) {
        DBG("right is down");
    }
}

To also get event from nested child components,I set:
addMouseListener(this,true);

Am I missing something or is this a Juce bug?

I have a temporary solution…I can recognize the right click with mousedown and set the modifier there:

void MyComponent::mouseDown(const juce::MouseEvent& e) {
    m_modKeys= e.mods;
}

This is not satisfying, but it works… Anyone else a better solution?

Component is actually giving you a separate callback to intercept mouse related events.

Assuming the Component instance is configured to intercept the mouse (ie: via setInterceptsMouseClicks), you should be overriding mouseDown or similar (whatever your use case).

I’m not sure I fully understand what you mean. What isn’t satisfactory about it?

1 Like

Ok, so it is intended to behave that way.

I see, thank you for telling me! I would have intuitively expected it to update the modifier when right click is pressed, eventhough setInterceptsMouseClicks is active…