30 : keyCode (code), mods (m), textCharacter (
textChar)
40 return keyCode ==
otherKeyCode && ! mods.isAnyModifierKeyDown();
45 return mods.getRawFlags() ==
other.mods.getRawFlags()
46 && (textCharacter ==
other.textCharacter
48 ||
other.textCharacter == 0)
49 && (keyCode ==
other.keyCode
51 &&
other.keyCode < 256
67namespace KeyPressHelpers
117 static const char* numberPadPrefix() noexcept {
return "numpad "; }
119 static int getNumpadKeyCode (
const String& desc)
121 if (desc.containsIgnoreCase (numberPadPrefix()))
123 auto lastChar = desc.trimEnd().getLastCharacter();
127 case '0':
case '1':
case '2':
case '3':
case '4':
128 case '5':
case '6':
case '7':
case '8':
case '9':
148 #if JUCE_MAC || JUCE_IOS
157 {
"shift + ", 0x21e7 },
158 {
"command + ", 0x2318 },
159 {
"option + ", 0x2325 },
160 {
"ctrl + ", 0x2303 },
161 {
"return", 0x21b5 },
162 {
"cursor left", 0x2190 },
163 {
"cursor right", 0x2192 },
164 {
"cursor up", 0x2191 },
165 {
"cursor down", 0x2193 },
166 {
"backspace", 0x232b },
167 {
"delete", 0x2326 },
168 {
"spacebar", 0x2423 }
180 modifiers |= KeyPressHelpers::modifierNames[i].flag;
188 key = KeyPressHelpers::translations[i].code;
194 key = KeyPressHelpers::getNumpadKeyCode (desc);
201 for (
int i = 1; i <= 35; ++i)
205 if (i <= 16) key =
F1Key + i - 1;
206 else if (i <= 24) key =
F17Key + i - 17;
207 else if (i <= 35) key =
F25Key + i - 25;
243 #if JUCE_MAC || JUCE_IOS
244 if (mods.
isAltDown()) desc <<
"option + ";
251 if (keyCode == KeyPressHelpers::translations[i].code)
252 return desc + KeyPressHelpers::translations[i].name;
255 if (keyCode >=
F1Key && keyCode <=
F16Key) desc <<
'F' << (1 + keyCode -
F1Key);
256 else if (keyCode >=
F17Key && keyCode <=
F24Key) desc <<
'F' << (17 + keyCode -
F17Key);
257 else if (keyCode >=
F25Key && keyCode <=
F35Key) desc <<
'F' << (25 + keyCode -
F25Key);
260 else if (keyCode ==
numberPadAdd) desc << KeyPressHelpers::numberPadPrefix() <<
'+';
261 else if (keyCode ==
numberPadSubtract) desc << KeyPressHelpers::numberPadPrefix() <<
'-';
262 else if (keyCode ==
numberPadMultiply) desc << KeyPressHelpers::numberPadPrefix() <<
'*';
263 else if (keyCode ==
numberPadDivide) desc << KeyPressHelpers::numberPadPrefix() <<
'/';
264 else if (keyCode ==
numberPadSeparator) desc << KeyPressHelpers::numberPadPrefix() <<
"separator";
266 else if (keyCode ==
numberPadEquals) desc << KeyPressHelpers::numberPadPrefix() <<
'=';
267 else if (keyCode ==
numberPadDelete) desc << KeyPressHelpers::numberPadPrefix() <<
"delete";
276 #if JUCE_MAC || JUCE_IOS
280 s = s.replace (KeyPressHelpers::osxSymbols[i].text,
static juce_wchar toLowerCase(juce_wchar character) noexcept
Converts a character to lower-case.
static juce_wchar toUpperCase(juce_wchar character) noexcept
Converts a character to upper-case.
Represents a key press, including any modifier keys that are needed.
static const int numberPadMultiply
key-code for the multiply sign on the numeric keypad.
String getTextDescriptionWithIcons() const
Creates a textual description of the key combination, using unicode icon symbols if possible.
static const int playKey
key-code for a multimedia 'play' key, (not all keyboards will have one)
static const int F35Key
key-code for the F35 key
static const int homeKey
key-code for the home key
static const int F24Key
key-code for the F24 key
static const int numberPadEquals
key-code for the equals key on the numeric keypad.
static const int upKey
key-code for the cursor-up key
KeyPress()=default
Creates an (invalid) KeyPress.
static const int F16Key
key-code for the F16 key
static const int fastForwardKey
key-code for a multimedia 'fast-forward' key, (not all keyboards will have one)
static const int stopKey
key-code for a multimedia 'stop' key, (not all keyboards will have one)
static const int numberPadSeparator
key-code for the comma on the numeric keypad.
static bool isKeyCurrentlyDown(int keyCode)
Checks whether a particular key is held down, irrespective of modifiers.
static const int endKey
key-code for the end key
static const int F1Key
key-code for the F1 key
static const int tabKey
key-code for the tab key
static const int numberPad0
key-code for the 0 on the numeric keypad.
static const int numberPad9
key-code for the 9 on the numeric keypad.
static const int numberPadAdd
key-code for the add sign on the numeric keypad.
static const int rightKey
key-code for the cursor-right key
static const int F17Key
key-code for the F17 key
static const int rewindKey
key-code for a multimedia 'rewind' key, (not all keyboards will have one)
static const int deleteKey
key-code for the delete key (not backspace)
static const int insertKey
key-code for the insert key
static const int F25Key
key-code for the F25 key
bool operator==(const KeyPress &other) const noexcept
Compares two KeyPress objects.
bool isCurrentlyDown() const
Checks whether the user is currently holding down the keys that make up this KeyPress.
static const int downKey
key-code for the cursor-down key
static const int numberPadDelete
key-code for the delete key on the numeric keypad.
static KeyPress createFromDescription(const String &textVersion)
Converts a textual key description to a KeyPress.
static const int spaceKey
key-code for the space bar
static const int escapeKey
key-code for the escape key
static const int numberPadDivide
key-code for the divide sign on the numeric keypad.
static const int returnKey
key-code for the return key
static const int leftKey
key-code for the cursor-left key
static const int pageUpKey
key-code for the page-up key
static const int pageDownKey
key-code for the page-down key
static const int numberPadDecimalPoint
key-code for the decimal point sign on the numeric keypad.
bool operator!=(const KeyPress &other) const noexcept
Compares two KeyPress objects.
static const int backspaceKey
key-code for the backspace key
static const int numberPadSubtract
key-code for the subtract sign on the numeric keypad.
String getTextDescription() const
Creates a textual description of the key combination.
Represents the state of the mouse buttons and modifier keys.
static ModifierKeys currentModifiers
This object represents the last-known state of the keyboard and mouse buttons.
bool isAltDown() const noexcept
Checks whether the ALT key's flag is set.
bool isCtrlDown() const noexcept
Checks whether the CTRL key's flag is 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 isShiftDown() const noexcept
Checks whether the shift key's flag is set.
@ ctrlModifier
CTRL key flag.
@ commandModifier
Command key flag - on windows this is the same as the CTRL key flag.
@ shiftModifier
Shift key flag.
@ allKeyboardModifiers
Represents a combination of all the shift, alt, ctrl and command key modifiers.
@ altModifier
ALT key flag.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
String retainCharacters(StringRef charactersToRetain) const
Returns a version of this string that only retains a fixed set of characters.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
static String charToString(juce_wchar character)
Creates a string from a single character.
juce_wchar getLastCharacter() const noexcept
Returns the final character of the string.
bool containsWholeWordIgnoreCase(StringRef wordToLookFor) const noexcept
Tests whether the string contains another substring as a distinct word.
String fromFirstOccurrenceOf(StringRef substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
Returns a section of the string starting from a given substring.
int getHexValue32() const noexcept
Parses the string as a hexadecimal number.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.