Beispiel #1
0
        /// <summary>
        /// Convert a keyCode and modifiers to a "Keys Down" string meant for Menu Items.
        /// </summary>
        public static string GetKeyMenuItemString(KeyCode keyCode, EventModifiers modifiers)
        {
            string keysDownString = "";

            if (modifiers.MatchesFlag(EventModifiers.Command))
            {
                keysDownString += "%";
            }
            if (modifiers.MatchesFlag(EventModifiers.Control))
            {
                keysDownString += "%";
            }
            if (modifiers.MatchesFlag(EventModifiers.Shift))
            {
                keysDownString += "#";
            }
            if (modifiers.MatchesFlag(EventModifiers.Alt))
            {
                keysDownString += "&";
            }

            keysDownString += keyCode.ToKeyString();

            return(keysDownString);
        }
Beispiel #2
0
        /// <summary>
        /// Convert a keyCode and modifiers to a "Keys Down" string meant for Menu Items.
        /// </summary>
        public static string GetKeyMenuItemString(KeyCode keyCode, EventModifiers modifiers)
        {
            string keysDownString = "_";

            #if UNITY_EDITOR_OSX
            if (modifiers.MatchesFlag(EventModifiers.Command))
            {
                keysDownString += "%";
            }
            #elif UNITY_EDITOR_WIN
            if (modifiers.MatchesFlag(EventModifiers.Control))
            {
                keysDownString += "%";
            }
            #endif
            if (modifiers.MatchesFlag(EventModifiers.Shift))
            {
                keysDownString += "#";
            }
            if (modifiers.MatchesFlag(EventModifiers.Alt))
            {
                keysDownString += "&";
            }

            var keyString = keyCode.ToKeyString();
            keysDownString += keyString;

            int  FNum          = 0;
            bool isNumericFkey = int.TryParse(keyString.Substring(1), out FNum);
            if (!isNumericFkey)
            {
                keysDownString = keysDownString.ToLower();                 //Must be lowercase if not F key (Mac).
            }
            return(keysDownString);
        }
Beispiel #3
0
        /// <summary>
        /// Returns true if two hotkeys along with their modifiers match
        /// </summary>
        public static bool HotkeysMatch(KeyCode hotkey, EventModifiers modifiers, KeyCode hotkey2, EventModifiers modifiers2)
        {
            if (hotkey == KeyCode.None || hotkey2 == KeyCode.None)
            {
                return(false);
            }
            var keyString = hotkey.ToKeyString();

            if (hotkey == hotkey2)
            {
                if (modifiers.MatchesFlag(EventModifiers.FunctionKey) != modifiers2.MatchesFlag(EventModifiers.FunctionKey) && keyString.Length > 1 && keyString.Substring(0, 1) == "F")
                {
                    //If a function key is pushed with no modifiers, the "FunctionKey" modifier is enabled. In this case, allow a match with no modifiers;
                    int  FNum          = 0;
                    bool isNumericFkey = int.TryParse(keyString.Substring(1), out FNum);
                    if (isNumericFkey)
                    {
                        modifiers  = modifiers | EventModifiers.FunctionKey;
                        modifiers2 = modifiers2 | EventModifiers.FunctionKey;
                    }
                }
                if (modifiers == modifiers2)
                {
                    return(true);
                }
            }
            return(false);
        }
        private static bool CheckHotkeyTriggered(KeyCode keyCode, EventModifiers modifiers, EditorFullscreenSettings.FullscreenOption fullscreenOption)
        {
            var keyString = keyCode.ToKeyString();

            if (keyCode == fullscreenOption.hotkey)
            {
                if (modifiers.MatchesFlag(EventModifiers.FunctionKey) != fullscreenOption.modifiers.MatchesFlag(EventModifiers.FunctionKey) && keyString.Length > 1 && keyString.Substring(0, 1) == "F")
                {
                    //If a function key is pushed with no modifiers, the "FunctionKey" modifier is enabled. In this case, allow a match with no modifiers;
                    int  FNum          = 0;
                    bool isNumericFkey = int.TryParse(keyString.Substring(1), out FNum);
                    if (isNumericFkey)
                    {
                        modifiers = fullscreenOption.modifiers | EventModifiers.FunctionKey;
                        fullscreenOption.modifiers = fullscreenOption.modifiers | EventModifiers.FunctionKey;
                    }
                }
                if (modifiers == fullscreenOption.modifiers)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #5
0
        public static string GetKeysDownString(List <KeyCode> keysDownList, EventModifiers modifiers)
        {
            var    keysDown       = new List <KeyCode>(keysDownList);
            string keysDownString = "";

            if (modifiers.MatchesFlag(EventModifiers.Command))
            {
                keysDownString += "Cmd+";
                keysDown.RemoveAll(kc => kc == KeyCode.LeftCommand || kc == KeyCode.RightCommand);
            }
            if (modifiers.MatchesFlag(EventModifiers.Control))
            {
                keysDownString += "Ctrl+";
                keysDown.RemoveAll(kc => kc == KeyCode.LeftControl || kc == KeyCode.RightControl);
            }
            if (modifiers.MatchesFlag(EventModifiers.Alt))
            {
                keysDownString += "Alt+";
                keysDown.RemoveAll(kc => kc == KeyCode.LeftAlt || kc == KeyCode.RightAlt);
            }
            if (modifiers.MatchesFlag(EventModifiers.Shift))
            {
                keysDownString += "Shift+";
                keysDown.RemoveAll(kc => kc == KeyCode.LeftShift || kc == KeyCode.RightShift);
            }
            if (modifiers.MatchesFlag(EventModifiers.CapsLock))
            {
                keysDownString += "Caps+";
                keysDown.RemoveAll(kc => kc == KeyCode.CapsLock);
            }

            for (int i = 0; i < keysDown.Count; i++)
            {
                if (keysDown[i] == KeyCode.LeftApple || keysDown[i] == KeyCode.RightApple)
                {
                    keysDownString += "Apple+";
                    keysDown[i]     = KeyCode.None;
                }
                if (keysDown[i] == KeyCode.LeftCommand || keysDown[i] == KeyCode.RightCommand)
                {
                    keysDownString += "Cmd+";
                    keysDown[i]     = KeyCode.None;
                }
                if (keysDown[i] == KeyCode.LeftControl || keysDown[i] == KeyCode.RightControl)
                {
                    keysDownString += "Ctrl+";
                    keysDown[i]     = KeyCode.None;
                }
                if (keysDown[i] == KeyCode.LeftAlt || keysDown[i] == KeyCode.RightAlt)
                {
                    keysDownString += "Alt+";
                    keysDown[i]     = KeyCode.None;
                }
                if (keysDown[i] == KeyCode.LeftShift || keysDown[i] == KeyCode.RightShift)
                {
                    keysDownString += "Shift+";
                    keysDown[i]     = KeyCode.None;
                }
            }

            foreach (KeyCode key in keysDown)
            {
                if (key != KeyCode.None)
                {
                    if (key == KeyCode.Space || key == KeyCode.PageUp || key == KeyCode.PageDown)
                    {
                        keysDownString += key.ToString() + "+";
                    }
                    else
                    {
                        keysDownString += key.ToKeyString() + "+";
                    }
                }
            }

            //Remove the last +
            if (keysDownString.Length > 1)
            {
                keysDownString = keysDownString.Substring(0, keysDownString.Length - 1);
            }

            return(keysDownString);
        }