Determine value of ModifierKeys when ComboBox is clicked?

I’d like to figure out, when I receive a selection in comboBoxChanged(), how to determine the state of the modifierKeys at that moment. I must be missing something obvious… not coming up with it so far… thanks!

I believe that modifier keys are only accessed through juce::MouseEvent objects, they won’t be registered by a ComboBox::Listener. My first thought if I needed modifier keys would be to override the mouseDown() function in the ComboBox’s parent component, then if the mouse is down within the ComboBox, check the mouse event’s key modifiers and do whatever needs to happen there.

1 Like

Thanks - but that seems kinda difficult, especially if you have multiple comboBoxes inside multiple different parent components.

One way that I just tested that seems to work, although I’m not sure of any ramifications, is to override Component::modifierKeysChanged in the MainWindow/MainComponent, and be informed of modifier changes globally anywhere in the app/plugin. Then store that value and query it when a comboBox selection is made… I’ve been playing with this for hours and that seems the easiest approach.

I’m somewhat surprised there isn’t an obvious way to do this, but maybe that’s obvious enough.

Sub-classing the ComboBox didn’t work, overriding all its mouse functions and even modifierKeysChanged() in the ComboBox itself, which doesn’t work because if the popupMenu is open, moving the mouse off the menu then has no way of updating the modifiers if you change them while the popup is showing but the mouse is not over it.

Overriding modifierKeysChanged() in the MainWindow even updates the modifier keys when the mouse is not over it, as long as it’s in front. Will have to test this more…

IIRC, inside your comboBoxChanged() you could call ModifierKeys::getCurrentModifiers() to see what are the current modifier keys

1 Like

But is that what you’d really want? If the ComboBox is attached to a parameter, then that function could be called due to automation, couldn’t it? You wouldn’t care about modifier key state in that instance. We derived a class from ComboBox and overrode onMouseDown/onMouseUp, etc., for our purposes, then call the base class functions to continue their work as normal.

But were you able to make it work for this case?
Let’s say you wanted to know if the alt key is down.

  1. click on ComboBox to display PopupMenu.
  2. with mouse over the popup menu’s area, press alt key down.
  3. choose item. Result is with alt key down.

now:

  1. click on ComboBox to display PopupMenu.
  2. with mouse over the popup menu’s area, press alt key down.
  3. drag down the items in the popup menu, and then drag off to the side, so the mouse is no longer over any part of the comboBox or its dropdown menu.
  4. release the alt key. User’s intent is he changed his mind, alt key is not down.
  5. choose item. Result is STILL with alt key down. (WRONG)

I tried a ComboBox derived class and overrode:
mouseDown
mouseEnter
mouseExit
mouseMove
modifierkeysChanged

…and I still couldn’t get any notification that the user had released the alt key in the above scenario before moving back to the open menu and choosing an item.

But if I store the results of modifierKeysChanged in my mainComponent, it always updates. Then again, I may have problems as you have suggested with automation this way; I’m not yet to that point…

You are right! I had completely forgotten about this after even using somewhere else in the project…