JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ModifierKeys.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
40class JUCE_API ModifierKeys
41{
42public:
43 //==============================================================================
45 ModifierKeys() = default;
46
53 ModifierKeys (int flags) noexcept;
54
56 ModifierKeys (const ModifierKeys&) = default;
57
59 ModifierKeys& operator= (const ModifierKeys&) = default;
60
61 //==============================================================================
68 inline bool isCommandDown() const noexcept { return testFlags (commandModifier); }
69
78 inline bool isPopupMenu() const noexcept { return testFlags (popupMenuClickModifier); }
79
81 inline bool isLeftButtonDown() const noexcept { return testFlags (leftButtonModifier); }
82
88 inline bool isRightButtonDown() const noexcept { return testFlags (rightButtonModifier); }
89
90 inline bool isMiddleButtonDown() const noexcept { return testFlags (middleButtonModifier); }
91
93 inline bool isAnyMouseButtonDown() const noexcept { return testFlags (allMouseButtonModifiers); }
94
96 inline bool isAnyModifierKeyDown() const noexcept { return testFlags ((shiftModifier | ctrlModifier | altModifier | commandModifier)); }
97
99 inline bool isShiftDown() const noexcept { return testFlags (shiftModifier); }
100
108 inline bool isCtrlDown() const noexcept { return testFlags (ctrlModifier); }
109
111 inline bool isAltDown() const noexcept { return testFlags (altModifier); }
112
113 //==============================================================================
115 enum Flags
116 {
118 noModifiers = 0,
119
121 shiftModifier = 1,
122
124 ctrlModifier = 2,
125
127 altModifier = 4,
128
130 leftButtonModifier = 16,
131
133 rightButtonModifier = 32,
134
136 middleButtonModifier = 64,
137
138 #if JUCE_MAC || JUCE_IOS
140 commandModifier = 8,
141
144 popupMenuClickModifier = rightButtonModifier | ctrlModifier,
145 #else
147 commandModifier = ctrlModifier,
148
151 popupMenuClickModifier = rightButtonModifier,
152 #endif
153
155 allKeyboardModifiers = shiftModifier | ctrlModifier | altModifier | commandModifier,
156
158 allMouseButtonModifiers = leftButtonModifier | rightButtonModifier | middleButtonModifier,
159
161 ctrlAltCommandModifiers = ctrlModifier | altModifier | commandModifier
162 };
163
164 //==============================================================================
166 [[nodiscard]] ModifierKeys withOnlyMouseButtons() const noexcept { return ModifierKeys (flags & allMouseButtonModifiers); }
167
169 [[nodiscard]] ModifierKeys withoutMouseButtons() const noexcept { return ModifierKeys (flags & ~allMouseButtonModifiers); }
170
171 bool operator== (const ModifierKeys other) const noexcept { return flags == other.flags; }
172 bool operator!= (const ModifierKeys other) const noexcept { return flags != other.flags; }
173
174 //==============================================================================
176 inline int getRawFlags() const noexcept { return flags; }
177
178 [[nodiscard]] ModifierKeys withoutFlags (int rawFlagsToClear) const noexcept { return ModifierKeys (flags & ~rawFlagsToClear); }
179 [[nodiscard]] ModifierKeys withFlags (int rawFlagsToSet) const noexcept { return ModifierKeys (flags | rawFlagsToSet); }
180
182 bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
183
185 int getNumMouseButtonsDown() const noexcept;
186
187 //==============================================================================
189 static ModifierKeys currentModifiers;
190
197 static ModifierKeys getCurrentModifiers() noexcept { return currentModifiers; }
198
205 static ModifierKeys getCurrentModifiersRealtime() noexcept;
206
207private:
208 int flags = 0;
209};
210
211} // namespace juce
Represents the state of the mouse buttons and modifier keys.
bool isRightButtonDown() const noexcept
Checks whether the flag is set for the right mouse-button.
bool isAltDown() const noexcept
Checks whether the ALT key's flag is set.
bool isAnyMouseButtonDown() const noexcept
Tests for any of the mouse-button flags.
bool testFlags(int flagsToTest) const noexcept
Tests a combination of flags and returns true if any of them are set.
ModifierKeys withOnlyMouseButtons() const noexcept
Returns a copy of only the mouse-button flags.
bool isCtrlDown() const noexcept
Checks whether the CTRL key's flag is set.
bool isLeftButtonDown() const noexcept
Checks whether the flag is set for the left mouse-button.
ModifierKeys(const ModifierKeys &)=default
Creates a copy of another object.
ModifierKeys()=default
Creates a ModifierKeys object with no flags set.
bool isCommandDown() const noexcept
Checks whether the 'command' key flag is set (or 'ctrl' on Windows/Linux).
int getRawFlags() const noexcept
Returns the raw flags for direct testing.
bool isAnyModifierKeyDown() const noexcept
Tests for any of the modifier key flags.
bool isPopupMenu() const noexcept
Checks whether the user is trying to launch a pop-up menu.
bool isShiftDown() const noexcept
Checks whether the shift key's flag is set.
Flags
Flags that represent the different keys.
ModifierKeys withoutMouseButtons() const noexcept
Returns a copy of only the non-mouse flags.
JUCE Namespace.