private bool IsExactMatch()
        {
            HashSet <KeyModifier> modifiers = this.GetKeyModifiers();
            HashSet <Key>         keys      = this.GetKeysPressed();

            // No key must be pressed for the modifier None.
            if (this.Contains(KeyModifier.None))
            {
                return((modifiers.Count == 0) &&
                       (keys.Count == 0));
            }

            // Make sure every modifier has a matching key pressed.
            foreach (KeyModifier modifier in modifiers)
            {
                if (!KeyModifierCollection.IsKeyPressed(modifier, keys))
                {
                    return(false);
                }
            }

            // Make sure every key pressed has a matching modifier.
            foreach (Key key in keys)
            {
                if (!KeyModifierCollection.HasModifier(key, modifiers))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo, object value)
        {
            KeyModifierCollection result = new KeyModifierCollection();
            string stringValue           = value as string;

            // convert null as None
            if (value == null ||
                (stringValue != null && stringValue.Trim() == string.Empty))
            {
                result.Add(KeyModifier.None);
            }
            else
            {
                // respect the following separators: '+', ' ', '|', or ','
                foreach (string token in stringValue.Split(new char[] { '+', ' ', '|', ',' },
                                                           StringSplitOptions.RemoveEmptyEntries))
                {
                    result.Add((KeyModifier)_keyModifierConverter.ConvertFrom(typeDescriptorContext, cultureInfo, token));
                }

                // if nothing added, assume None
                if (result.Count == 0)
                {
                    result.Add(KeyModifier.None);
                }
            }
            return(result);
        }
        private bool MatchAny()
        {
            if (this.Contains(KeyModifier.None))
            {
                return(true);
            }

            HashSet <KeyModifier> modifiers = this.GetKeyModifiers();
            HashSet <Key>         keys      = this.GetKeysPressed();

            foreach (KeyModifier modifier in modifiers)
            {
                if (KeyModifierCollection.IsKeyPressed(modifier, keys))
                {
                    return(true);
                }
            }

            return(false);
        }