JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ModifierKeys Class Reference

Represents the state of the mouse buttons and modifier keys. More...

#include <juce_ModifierKeys.h>

Collaboration diagram for juce::ModifierKeys:

Public Types

enum  Flags {
  noModifiers = 0,
  shiftModifier = 1,
  ctrlModifier = 2,
  altModifier = 4,
  leftButtonModifier = 16,
  rightButtonModifier = 32,
  middleButtonModifier = 64,
  commandModifier = 8,
  popupMenuClickModifier = rightButtonModifier | ctrlModifier,
  allKeyboardModifiers = shiftModifier | ctrlModifier | altModifier | commandModifier,
  allMouseButtonModifiers = leftButtonModifier | rightButtonModifier | middleButtonModifier,
  ctrlAltCommandModifiers = ctrlModifier | altModifier | commandModifier
}
 Flags that represent the different keys. More...
 

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Private Attributes

int flags = 0
 

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

@tags{GUI}

Member Enumeration Documentation

◆ 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.

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.

Constructor & Destructor Documentation

◆ ModifierKeys() [1/3]

juce::ModifierKeys::ModifierKeys ( )
default

Creates a ModifierKeys object with no flags set.

◆ ModifierKeys() [2/3]

juce::ModifierKeys::ModifierKeys ( int  flags)
noexcept

Creates a ModifierKeys object from a raw set of flags.

Parameters
flagsto 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.

Member Function Documentation

◆ getCurrentModifiers()

static ModifierKeys juce::ModifierKeys::getCurrentModifiers ( )
inlinestaticnoexcept

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.

◆ getCurrentModifiersRealtime()

static ModifierKeys juce::ModifierKeys::getCurrentModifiersRealtime ( )
staticnoexcept

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).

◆ getNumMouseButtonsDown()

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

Returns the total number of mouse buttons that are down.

◆ getRawFlags()

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

Returns the raw flags for direct testing.

References juce::gl::flags.

◆ isAltDown()

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

Checks whether the ALT key's flag is set.

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

◆ isAnyModifierKeyDown()

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

Tests for any of the modifier key flags.

◆ isAnyMouseButtonDown()

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

Tests for any of the mouse-button flags.

◆ isCommandDown()

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

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.

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

◆ isCtrlDown()

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

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

◆ isLeftButtonDown()

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

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

◆ isMiddleButtonDown()

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

◆ isPopupMenu()

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

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.

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

◆ isRightButtonDown()

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

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).

◆ isShiftDown()

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

◆ operator!=()

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

References juce::gl::flags.

◆ operator=()

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

Copies this object from another one.

◆ operator==()

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

References juce::gl::flags.

◆ testFlags()

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

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

References juce::gl::flags.

◆ withFlags()

JUCE_NODISCARD ModifierKeys juce::ModifierKeys::withFlags ( int  rawFlagsToSet) const
inlinenoexcept

References juce::gl::flags.

◆ withOnlyMouseButtons()

JUCE_NODISCARD ModifierKeys juce::ModifierKeys::withOnlyMouseButtons ( ) const
inlinenoexcept

Returns a copy of only the mouse-button flags.

References juce::gl::flags.

◆ withoutFlags()

JUCE_NODISCARD ModifierKeys juce::ModifierKeys::withoutFlags ( int  rawFlagsToClear) const
inlinenoexcept

References juce::gl::flags.

◆ withoutMouseButtons()

JUCE_NODISCARD ModifierKeys juce::ModifierKeys::withoutMouseButtons ( ) const
inlinenoexcept

Returns a copy of only the non-mouse flags.

References juce::gl::flags.

Member Data Documentation

◆ currentModifiers

ModifierKeys juce::ModifierKeys::currentModifiers
static

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

◆ flags

int juce::ModifierKeys::flags = 0
private

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