Loading...
Searching...
No Matches
juce::ModifierKeys Class Reference

## Detailed Description

Represents the state of the mouse buttons and modifier keys.

This is used both by mouse events and by KeyPress objects to describe the state of keys such as shift, control, alt, etc.

See also
  KeyPress, MouseEvent::mods

The documentation for this class was generated from the following file:

- juce_gui_basics/keyboard/juce_ModifierKeys.h

## Public Types

enum

Flags {
noModifiers = 0 , shiftModifier = 1 , ctrlModifier = 2 , altModifier = 4 ,
leftButtonModifier = 16 , rightButtonModifier = 32 , middleButtonModifier = 64 , backButtonModifier = 128 ,
forwardButtonModifier = 256 , commandModifier = 8 , popupMenuClickModifier = rightButtonModifier | ctrlModifier , allKeyboardModifiers = shiftModifier | ctrlModifier | altModifier | commandModifier ,
allMouseButtonModifiers , ctrlAltCommandModifiers = ctrlModifier | altModifier | commandModifier
}

| Flags that represent the different keys. More...

## Public Member Functions

| ModifierKeys ()=default
| Creates a ModifierKeys object with no flags set.
| ModifierKeys (int flags) noexcept
| Creates a ModifierKeys object from a raw set of flags.
| ModifierKeys (const ModifierKeys &)=default
| Creates a copy of another object.
ModifierKeys & | operator= (const ModifierKeys &)=default
| Copies this object from another one.
bool | isCommandDown () const noexcept
| Checks whether the 'command' key flag is set (or 'ctrl' on Windows/Linux).
bool | isPopupMenu () const noexcept
| Checks whether the user is trying to launch a pop-up menu.
bool | isLeftButtonDown () const noexcept
| Checks whether the flag is set for the left mouse-button.
bool | isRightButtonDown () const noexcept
| Checks whether the flag is set for the right mouse-button.
bool | isMiddleButtonDown () const noexcept
bool | isBackButtonDown () const noexcept
bool | isForwardButtonDown () const noexcept
bool | isAnyMouseButtonDown () const noexcept
| Tests for any of the mouse-button flags.
bool | isAnyModifierKeyDown () const noexcept
| Tests for any of the modifier key flags.
bool | isShiftDown () const noexcept
| Checks whether the shift key's flag is set.
bool | isCtrlDown () const noexcept
| Checks whether the CTRL key's flag is set.
bool | isAltDown () const noexcept
| Checks whether the ALT key's flag is set.
ModifierKeys | withOnlyMouseButtons () const noexcept
| Returns a copy of only the mouse-button flags.
ModifierKeys | withoutMouseButtons () const noexcept
| Returns a copy of only the non-mouse flags.
bool | operator== (const ModifierKeys other) const noexcept
bool | operator!= (const ModifierKeys other) const noexcept
int | getRawFlags () const noexcept
| Returns the raw flags for direct testing.
ModifierKeys | withoutFlags (int rawFlagsToClear) const noexcept
ModifierKeys | withFlags (int rawFlagsToSet) const noexcept
bool | testFlags (int flagsToTest) const noexcept
| Tests a combination of flags and returns true if any of them are set.
int | getNumMouseButtonsDown () const noexcept
| Returns the total number of mouse buttons that are down.

## Static Public Member Functions

static ModifierKeys | getCurrentModifiers () noexcept
| Creates a ModifierKeys object to represent the last-known state of the keyboard and mouse buttons.
static ModifierKeys | getCurrentModifiersRealtime () noexcept
| Creates a ModifierKeys object to represent the current state of the keyboard and mouse buttons.

## Static Public Attributes

static ModifierKeys | currentModifiers
| This object represents the last-known state of the keyboard and mouse buttons.

## Member Enums

## Flags

enum juce::ModifierKeys::Flags

Flags that represent the different keys.

Enumerator
noModifiers | Indicates no modifier keys.
shiftModifier | Shift key flag.
ctrlModifier | CTRL key flag.
altModifier | ALT key flag.
leftButtonModifier | Left mouse button flag.
rightButtonModifier | Right mouse button flag.
middleButtonModifier | Middle mouse button flag.
backButtonModifier |
forwardButtonModifier |
commandModifier | Command key flag - on windows this is the same as the CTRL key flag.
popupMenuClickModifier | Popup menu flag - on windows this is the same as rightButtonModifier, on the Mac it's the same as (rightButtonModifier | ctrlModifier).
allKeyboardModifiers | Represents a combination of all the shift, alt, ctrl and command key modifiers.
allMouseButtonModifiers | Represents a combination of all the mouse buttons at once.
ctrlAltCommandModifiers | Represents a combination of all the alt, ctrl and command key modifiers.

## Constructors and Destructors

## ModifierKeys() [1/3]

juce::ModifierKeys::ModifierKeys | ( |  | ) |

default

Creates a ModifierKeys object with no flags set.

Referenced by getCurrentModifiers(), getCurrentModifiersRealtime(), ModifierKeys(), operator!=(), operator=(), operator==(), withFlags(), withOnlyMouseButtons(), withoutFlags(), and withoutMouseButtons().

## ModifierKeys() [2/3]

juce::ModifierKeys::ModifierKeys | ( | int | flags | ) |

noexcept

Creates a ModifierKeys object from a raw set of flags.

Parameters

  flags | to represent the keys that are down

See also
  shiftModifier, ctrlModifier, altModifier, leftButtonModifier, rightButtonModifier, commandModifier, popupMenuClickModifier

## ModifierKeys() [3/3]

juce::ModifierKeys::ModifierKeys | ( | const ModifierKeys & |  | ) |

default

Creates a copy of another object.

References ModifierKeys().

## Member Functions

## operator=()

ModifierKeys & juce::ModifierKeys::operator= | ( | const ModifierKeys & |  | ) |

default

Copies this object from another one.

References ModifierKeys().

## isCommandDown()

bool juce::ModifierKeys::isCommandDown | ( |  | ) | const

inline noexcept

Checks whether the 'command' key flag is set (or 'ctrl' on Windows/Linux).

This is a platform-agnostic way of checking for the operating system's preferred command-key modifier - so on the Mac it tests for the cmd key, on Windows/Linux, it's actually checking for the CTRL key.

References commandModifier, and testFlags().

Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers(), and juce::LassoComponent< SelectableItemType >::dragLasso().

## isPopupMenu()

bool juce::ModifierKeys::isPopupMenu | ( |  | ) | const

inline noexcept

Checks whether the user is trying to launch a pop-up menu.

This checks for platform-specific modifiers that might indicate that the user is following the operating system's normal method of showing a pop-up menu.

So on Windows/Linux, this method is really testing for a right-click. On the Mac, it tests for either the CTRL key being down, or a right-click.

References popupMenuClickModifier, and testFlags().

Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionOnMouseDown().

## isLeftButtonDown()

bool juce::ModifierKeys::isLeftButtonDown | ( |  | ) | const

inline noexcept

Checks whether the flag is set for the left mouse-button.

References leftButtonModifier, and testFlags().

## isRightButtonDown()

bool juce::ModifierKeys::isRightButtonDown | ( |  | ) | const

inline noexcept

Checks whether the flag is set for the right mouse-button.

Note that for detecting popup-menu clicks, you should be using isPopupMenu() instead, as this is platform-independent (and makes your code more explanatory too).

References rightButtonModifier, and testFlags().

## isMiddleButtonDown()

bool juce::ModifierKeys::isMiddleButtonDown | ( |  | ) | const

inline noexcept

References middleButtonModifier, and testFlags().

## isBackButtonDown()

bool juce::ModifierKeys::isBackButtonDown | ( |  | ) | const

inline noexcept

References backButtonModifier, and testFlags().

## isForwardButtonDown()

bool juce::ModifierKeys::isForwardButtonDown | ( |  | ) | const

inline noexcept

References forwardButtonModifier, and testFlags().

## isAnyMouseButtonDown()

bool juce::ModifierKeys::isAnyMouseButtonDown | ( |  | ) | const

inline noexcept

Tests for any of the mouse-button flags.

References allMouseButtonModifiers, and testFlags().

## isAnyModifierKeyDown()

bool juce::ModifierKeys::isAnyModifierKeyDown | ( |  | ) | const

inline noexcept

Tests for any of the modifier key flags.

References altModifier, commandModifier, ctrlModifier, shiftModifier, and testFlags().

## isShiftDown()

bool juce::ModifierKeys::isShiftDown | ( |  | ) | const

inline noexcept

Checks whether the shift key's flag is set.

References shiftModifier, and testFlags().

Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers(), and juce::LassoComponent< SelectableItemType >::dragLasso().

## isCtrlDown()

bool juce::ModifierKeys::isCtrlDown | ( |  | ) | const

inline noexcept

Checks whether the CTRL key's flag is set.

Remember that it's better to use the platform-agnostic routines to test for command-key and popup-menu modifiers.

See also
  isCommandDown, isPopupMenu

References ctrlModifier, and testFlags().

## isAltDown()

bool juce::ModifierKeys::isAltDown | ( |  | ) | const

inline noexcept

Checks whether the ALT key's flag is set.

References altModifier, and testFlags().

Referenced by juce::LassoComponent< SelectableItemType >::dragLasso().

## withOnlyMouseButtons()

ModifierKeys juce::ModifierKeys::withOnlyMouseButtons | ( |  | ) | const

inline nodiscard noexcept

Returns a copy of only the mouse-button flags.

References allMouseButtonModifiers, and ModifierKeys().

## withoutMouseButtons()

ModifierKeys juce::ModifierKeys::withoutMouseButtons | ( |  | ) | const

inline nodiscard noexcept

Returns a copy of only the non-mouse flags.

References allMouseButtonModifiers, and ModifierKeys().

## operator==()

bool juce::ModifierKeys::operator== | ( | const ModifierKeys | other | ) | const

inline noexcept

References ModifierKeys().

## operator!=()

bool juce::ModifierKeys::operator!= | ( | const ModifierKeys | other | ) | const

inline noexcept

References ModifierKeys().

## getRawFlags()

int juce::ModifierKeys::getRawFlags | ( |  | ) | const

inline noexcept

Returns the raw flags for direct testing.

## withoutFlags()

ModifierKeys juce::ModifierKeys::withoutFlags | ( | int | rawFlagsToClear | ) | const

inline nodiscard noexcept

References ModifierKeys().

## withFlags()

ModifierKeys juce::ModifierKeys::withFlags | ( | int | rawFlagsToSet | ) | const

inline nodiscard noexcept

References ModifierKeys().

## testFlags()

bool juce::ModifierKeys::testFlags | ( | int | flagsToTest | ) | const

inline noexcept

Tests a combination of flags and returns true if any of them are set.

Referenced by isAltDown(), isAnyModifierKeyDown(), isAnyMouseButtonDown(), isBackButtonDown(), isCommandDown(), isCtrlDown(), isForwardButtonDown(), isLeftButtonDown(), isMiddleButtonDown(), isPopupMenu(), isRightButtonDown(), and isShiftDown().

## getNumMouseButtonsDown()

int juce::ModifierKeys::getNumMouseButtonsDown | ( |  | ) | const

noexcept

Returns the total number of mouse buttons that are down.

## getCurrentModifiers()

ModifierKeys juce::ModifierKeys::getCurrentModifiers | ( |  | ) |

inline static noexcept

Creates a ModifierKeys object to represent the last-known state of the keyboard and mouse buttons.

This method is here for backwards compatibility and there's no need to call it anymore, you should use the public currentModifiers member directly.

References currentModifiers, getCurrentModifiers(), and ModifierKeys().

Referenced by getCurrentModifiers().

## getCurrentModifiersRealtime()

ModifierKeys juce::ModifierKeys::getCurrentModifiersRealtime | ( |  | ) |

static noexcept

Creates a ModifierKeys object to represent the current state of the keyboard and mouse buttons.

This method is here for backwards compatibility and you should call ComponentPeer::getCurrentModifiersRealtime() instead (which is what this method now does).

References ModifierKeys().

## Member Data Documentation

## currentModifiers

ModifierKeys juce::ModifierKeys::currentModifiers

static

This object represents the last-known state of the keyboard and mouse buttons.

Referenced by getCurrentModifiers().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited