| 1769 | |
| 1770 | |
| 1771 | ResultType Hotkey::TextToKey(LPTSTR aText, bool aIsModifier, Hotkey *aThisHotkey) |
| 1772 | // This function and those it calls should avoid showing any error dialogs when caller passes NULL for |
| 1773 | // aThisHotkey (however, there is at least one exception explained in comments below where it occurs). |
| 1774 | // Caller must ensure that aText is a modifiable string. |
| 1775 | // Takes input param aText to support receiving only a subset of mName. |
| 1776 | // In private members, sets the values of vk/sc or ModifierVK/ModifierSC depending on aIsModifier. |
| 1777 | // It may also merge new modifiers into the existing value of modifiers, so the caller |
| 1778 | // should never reset modifiers after calling this. |
| 1779 | // Returns OK or FAIL. |
| 1780 | { |
| 1781 | vk_type temp_vk; // No need to initialize this one. |
| 1782 | sc_type temp_sc = 0; |
| 1783 | modLR_type modifiersLR = 0; |
| 1784 | bool is_mouse = false; |
| 1785 | int joystick_id; |
| 1786 | |
| 1787 | HotkeyTypeType hotkey_type_temp; |
| 1788 | HotkeyTypeType &hotkey_type = aThisHotkey ? aThisHotkey->mType : hotkey_type_temp; // Simplifies and reduces code size below. |
| 1789 | |
| 1790 | if (!aIsModifier) |
| 1791 | { |
| 1792 | // Previous steps should make it unnecessary to call omit_leading_whitespace(aText). |
| 1793 | LPTSTR cp = StrChrAny(aText, _T(" \t")); // Find first space or tab. |
| 1794 | if (cp && !_tcsicmp(omit_leading_whitespace(cp), _T("Up"))) |
| 1795 | { |
| 1796 | // This is a key-up hotkey, such as "Ctrl Up::". |
| 1797 | if (aThisHotkey) |
| 1798 | aThisHotkey->mKeyUp = true; |
| 1799 | *cp = '\0'; // Terminate at the first space so that the word "up" is removed from further consideration by us and callers. |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | if (temp_vk = TextToVK(aText, &modifiersLR, true)) // Assign. |
| 1804 | { |
| 1805 | if (aIsModifier) |
| 1806 | { |
| 1807 | if (IS_WHEEL_VK(temp_vk)) |
| 1808 | { |
| 1809 | ValueError(ERR_UNSUPPORTED_PREFIX, aText, FAIL); |
| 1810 | // When aThisHotkey==NULL, return CONDITION_FALSE to indicate to our caller that it's |
| 1811 | // an invalid hotkey and we've already shown the error message. Unlike the old method, |
| 1812 | // this method respects /ErrorStdOut and avoids the second, generic error message. |
| 1813 | if (!aThisHotkey) |
| 1814 | return CONDITION_FALSE; |
| 1815 | return FAIL; |
| 1816 | } |
| 1817 | } |
| 1818 | else |
| 1819 | // This is done here rather than at some later stage because we have access to the raw |
| 1820 | // name of the suffix key (with any leading modifiers such as ^ omitted from the beginning): |
| 1821 | if (aThisHotkey) |
| 1822 | aThisHotkey->mVK_WasSpecifiedByNumber = !_tcsnicmp(aText, _T("VK"), 2); |
| 1823 | is_mouse = IsMouseVK(temp_vk); |
| 1824 | if (modifiersLR & (MOD_LSHIFT | MOD_RSHIFT)) |
| 1825 | if (temp_vk >= 'A' && temp_vk <= 'Z') // VK of an alpha char is the same as the ASCII code of its uppercase version. |
| 1826 | modifiersLR &= ~(MOD_LSHIFT | MOD_RSHIFT); |
| 1827 | // Above: Making alpha chars case insensitive seems much more friendly. In other words, |
| 1828 | // if the user defines ^Z as a hotkey, it will really be ^z, not ^+z. By removing SHIFT |
nothing calls this directly
no test coverage detected