Ejemplo n.º 1
0
        static public KBShortcut FromString(string str)
        {
            var result = new KBShortcut();

            if (str[0] == '_')
            {
                result.code = (KeyCode)Enum.Parse(typeof(KeyCode), str.Substring(1));
            }
            else
            {
                var cnt = 0;
                if (str.IndexOf('#') != -1)
                {
                    result.shift = true;
                    cnt++;
                }
                if (str.IndexOf('%') != -1)
                {
                    result.ctrl = true;
                    cnt++;
                }
                if (str.IndexOf('&') != -1)
                {
                    result.alt = true;
                    cnt++;
                }

                result.code = (KeyCode)Enum.Parse(typeof(KeyCode), str.Substring(cnt));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static void Check()
        {
            var e = Event.current;

            if (e.type != EventType.keyDown || e.keyCode == KeyCode.None)
            {
                return;
            }

            var hasKeyChain = keyChain.code != KeyCode.None && keyChain.ctrl == e.control && keyChain.alt == e.alt && keyChain.shift == e.shift;
            var shortcut    = new KBShortcut {
                ctrl  = e.control,
                alt   = e.alt,
                shift = e.shift,
                chain = hasKeyChain ? keyChain.code : KeyCode.None,
                code  = e.keyCode
            };

            //if (hasKeyChain) {
            //    Debug.Log("Key chain detected ::: " + shortcut + "--->" + e.keyCode);
            //}

            if (_keyMap.ContainsKey(shortcut))
            {
                keyChain.code = KeyCode.None; //clear keyChain
                //Debug.Log("clear chain ::: " + keyChain.code);
                _keyMap[shortcut]();
                return;
            }

            if (hasKeyChain)
            {
                shortcut.chain = KeyCode.None;

                if (_keyMap.ContainsKey(shortcut))
                {
                    keyChain.code = KeyCode.None;
                    _keyMap[shortcut]();
                    //Debug.Log("key chain unmatched :: check normal OK " + shortcut);
                    return;
                }
            }


            if (e.keyCode != KeyCode.None)
            {
                keyChain = shortcut;
                //Debug.Log("Save chain ::: " + keyChain.code);
            }
        }
Ejemplo n.º 3
0
        /*public static bool Add(string shortcut, Action act) {
         *  return Add(KBShortcut.FromString(shortcut), act);
         * }*/

        public static bool Add(KBShortcut key, Action act)
        {
            if (key.code == KeyCode.None)
            {
                return(false);
            }

            if (_keyMap == null)
            {
                _keyMap = new Dictionary <KBShortcut, Action>();
            }
            if (_keyMap.ContainsKey(key))
            {
                Debug.LogWarning("Duplicated key : " + key + " found, ignoring ...");
                return(false);
            }

            _keyMap[key] = act;
            return(true);
        }