Пример #1
0
 public static bool ParseMeta(ref MetaKey meta, string str)
 {
     if (string.Compare(str, "shift", true) == 0)
     {
         meta |= MetaKey.Shift;
         return(true);
     }
     else if (string.Compare(str, "control", true) == 0)
     {
         meta |= MetaKey.Control;
         return(true);
     }
     else if (string.Compare(str, "windows", true) == 0)
     {
         meta |= MetaKey.Super;
         return(true);
     }
     else if (string.Compare(str, "command", true) == 0)
     {
         meta |= MetaKey.Super;
         return(true);
     }
     else if (string.Compare(str, "super", true) == 0)
     {
         meta |= MetaKey.Super;
         return(true);
     }
     return(false);
 }
Пример #2
0
 public KeyCombo(string keyName, MetaKey meta = 0)
 {
     _keyName = keyName;
     // Using _editorMeta is not important, but helps avoid a build warning.
     _editorMeta = meta;
     _meta       = _editorMeta;
 }
Пример #3
0
        public static bool MetaReleased(MetaKey meta, InputLayer layer)
        {
            // FIXME: this is not precise enough for multiple meta combos.
            bool active = true;

            if ((meta & MetaKey.Shift) != 0 &&
                !layer.GetKeyUp(KeyCode.LeftShift) && !layer.GetKeyUp(KeyCode.RightShift))
            {
                active = false;
            }

            if ((meta & MetaKey.Alt) != 0 &&
                !layer.GetKeyUp(KeyCode.LeftAlt) && !layer.GetKeyUp(KeyCode.RightAlt))
            {
                active = false;
            }

            if ((meta & MetaKey.Control) != 0 &&
                !layer.GetKeyUp(KeyCode.LeftControl) && !layer.GetKeyUp(KeyCode.RightControl))
            {
                active = false;
            }

            if ((meta & MetaKey.Super) != 0 &&
                !layer.GetKeyUp(KeyCode.LeftCommand) && !layer.GetKeyUp(KeyCode.RightCommand) &&
                !layer.GetKeyUp(KeyCode.LeftWindows) && !layer.GetKeyUp(KeyCode.RightWindows))
            {
                active = false;
            }

            return(active);
        }
Пример #4
0
 public KeyCombo(KeyCode code, MetaKey meta = 0)
 {
     _keyCode = code;
     // Using _editorMeta is not important, but helps avoid a build warning.
     _editorMeta = meta;
     _meta       = _editorMeta;
 }
Пример #5
0
 public static bool MatchMetaState(MetaKey meta, InputLayer layer, MetaKey testFlag, KeyCode key1, KeyCode key2, KeyCode key3, KeyCode key4)
 {
     if ((meta & testFlag) != 0 && !layer.GetKey(key1) && !layer.GetKey(key2) && !layer.GetKey(key3) && !layer.GetKey(key4) ||
         (meta & testFlag) == 0 && (layer.GetKey(key1) || layer.GetKey(key2) || layer.GetKey(key3) || layer.GetKey(key4)))
     {
         return(false);
     }
     return(true);
 }
Пример #6
0
        public static bool MetaActive(MetaKey meta, InputLayer layer)
        {
            // FIXME: this is not precise enough for multiple meta combos.
            bool active = true;

            active = active && MatchMetaState(meta, layer, MetaKey.Shift, KeyCode.LeftShift, KeyCode.RightShift);
            active = active && MatchMetaState(meta, layer, MetaKey.Alt, KeyCode.LeftAlt, KeyCode.RightAlt);
            active = active && MatchMetaState(meta, layer, MetaKey.Control, KeyCode.LeftControl, KeyCode.RightControl);
            active = active && MatchMetaState(meta, layer, MetaKey.Super, KeyCode.LeftWindows, KeyCode.RightWindows, KeyCode.LeftCommand, KeyCode.RightCommand);

            return(active);
        }
Пример #7
0
        private bool RequireMetaKey(MetaKey key, params MetaData[] items)
        {
            bool result = true;

            foreach (MetaData item in items)
            {
                if (!item.Data.ContainsKey(key))
                {
                    Trace.WriteLine($"[MediaQuerier] required meta key \"{key}\" not found in file: {item.Path}");
                    result = false;
                }
            }

            return(result);
        }
Пример #8
0
        public bool Parse(string sequence)
        {
            string[] parts   = sequence.Split(new char[] { '+' });
            string   keyName = null;
            MetaKey  meta    = 0;

            for (int i = 0; i < parts.Length; ++i)
            {
                if (!ParseMeta(ref meta, parts[i]))
                {
                    if (keyName != null)
                    {
                        // Multiple keys specified.
                        return(false);
                    }
                    keyName = parts[i];
                }
            }

            if (keyName == null)
            {
                // No key.
                return(false);
            }

            _meta = meta;
            if (ParseKey(ref _keyCode, keyName))
            {
                _keyName = null;
            }
            else
            {
                _keyCode = KeyCode.None;
                _keyName = keyName;
            }
            return(true);
        }
Пример #9
0
 public static bool MatchMetaState(MetaKey meta, InputLayer layer, MetaKey testFlag, KeyCode key)
 {
     return(MatchMetaState(meta, layer, testFlag, key, key));
 }
Пример #10
0
 /// <summary>
 /// Get the metadata value of the specified key.
 /// </summary>
 public string this[MetaKey key] {
     get {
         string value;
         return(Metadata.TryGetValue(key, out value) ? value : string.Empty);
     }
 }