Is 'Ctrl' key pressed while clicking a button?

matlab, user-interface

Solution

How about this:

modifiers = get(gcf,'currentModifier');        %(Use an actual figure number if known)
ctrlIsPressed = ismember('control',modifiers);

The figure class has a number of useful `Current*` properties which are useful when handling callbacks. This is how to retrieve current mouse position, selected graphics object, and (as here) pressed keys. These include: CurrentAxes, CurrentCharacter, CurrentKey, CurrentModifier, CurrentObject, and CurrentPosition.

Problem

I need to know whether the user is holding down the ctrl key while clicking a button. Since it's a button and not a figure I cannot use 'selectionType' on the figure etc.

Original source