MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / TextToModifiers

Method TextToModifiers

source/hotkey.cpp:1597–1767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1595
1596
1597LPTSTR Hotkey::TextToModifiers(LPTSTR aText, Hotkey *aThisHotkey, HotkeyProperties *aProperties)
1598// This function and those it calls should avoid showing any error dialogs when caller passes NULL for aThisHotkey.
1599// Takes input param <text> to support receiving only a subset of object.text.
1600// Returns the location in <text> of the first non-modifier key.
1601// Checks only the first char(s) for modifiers in case these characters appear elsewhere (e.g. +{+}).
1602// But come to think of it, +{+} isn't valid because + itself is already shift-equals. So += would be
1603// used instead, e.g. +==action. Similarly, all the others, except =, would be invalid as hotkeys also.
1604// UPDATE: On some keyboard layouts, the + key and various others don't require the shift key to be
1605// manifest. Thus, on these systems a hotkey such as ^+:: is now supported as meaning Ctrl-Plus.
1606{
1607 // Init output parameter for caller if it gave one:
1608 if (aProperties)
1609 ZeroMemory(aProperties, sizeof(HotkeyProperties));
1610
1611 if (!*aText)
1612 return aText; // Below relies on this having ensured that aText isn't blank.
1613
1614 // Explicitly avoids initializing modifiers to 0 because the caller may have already included
1615 // some set some modifiers in there.
1616 LPTSTR marker;
1617 bool key_left, key_right;
1618
1619 // Simplifies and reduces code size below:
1620 mod_type temp_modifiers;
1621 mod_type &modifiers = aProperties ? aProperties->modifiers : (aThisHotkey ? aThisHotkey->mModifiers : temp_modifiers);
1622 modLR_type temp_modifiersLR;
1623 modLR_type &modifiersLR = aProperties ? aProperties->modifiersLR: (aThisHotkey ? aThisHotkey->mModifiersLR : temp_modifiersLR);
1624
1625 // Improved for v1.0.37.03: The loop's condition is now marker[1] vs. marker[0] so that
1626 // the last character is never considered a modifier. This allows a modifier symbol
1627 // to double as the name of a suffix key. It also fixes issues on layouts where the
1628 // symbols +^#! do not require the shift key to be held down, such as the German layout.
1629 //
1630 // Improved for v1.0.40.01: The loop's condition now stops when it reaches a single space followed
1631 // by the word "Up" so that hotkeys like "< up" and "+ up" are supported by seeing their '<' or '+' as
1632 // a key name rather than a modifier symbol.
1633 // Fix for v1.1.27.05: Stop at any space, not just " up", so that " & " is also covered.
1634 // This fixes "> & v" to not interpret ">" as a modifier. This also causes "+ ::" to be
1635 // seen as invalid, where previously TextToModifiers() saw it as Shift+Space but a later
1636 // stage trimmed the space and registered "+::". This is best since trailing spaces are
1637 // not allowed in any other hotkeys, and even "+ ::" (two spaces) was not allowed.
1638 for (marker = aText, key_left = false, key_right = false; marker[1] && marker[1] != ' '; ++marker)
1639 {
1640 switch (*marker)
1641 {
1642 case '>':
1643 key_right = true;
1644 break;
1645 case '<':
1646 key_left = true;
1647 break;
1648 case '*':
1649 if (aThisHotkey)
1650 aThisHotkey->mAllowExtraModifiers = true;
1651 if (aProperties)
1652 aProperties->has_asterisk = true;
1653 break;
1654 case '~':

Callers

nothing calls this directly

Calls 3

omit_trailing_whitespaceFunction · 0.85
omit_leading_whitespaceFunction · 0.85
tcscasestrFunction · 0.85

Tested by

no test coverage detected