Beispiel #1
0
        /// <summary>
        /// Attemp to parse out a <code>ModifiedKey</code> from a string.
        /// The string should be of the form CSAW-L where the part before the '-'
        /// is the modifiers and is optional, and the part afterwards is the Key
        /// from the <code>Keys</code> enumeration.
        /// </summary>
        /// <param name="s">String to parse.</param>
        /// <param name="result">Parsed object.</param>
        /// <returns>True if the parsing succeeds, false otherwise.</returns>
        public static bool TryParse(string s, out ModifiedKey result)
        {
            result = null;

            if (String.IsNullOrWhiteSpace(s))
            {
                return(false);
            }

            s = s.Trim();

            string[] parts = s.Split('-');
            if (parts.Length == 1)
            {
                // Could be "L" or "PgUp" but not modified.
                Keys k;
                if (!Enum.TryParse(parts[0], out k))
                {
                    return(false);
                }

                result = new ModifiedKey(Modifiers.None, k);
                return(true);
            }
            else if (parts.Length == 2)
            {
                // Could be "CS-L" or some variant.
                Keys k;
                if (!Enum.TryParse(parts[1], out k))
                {
                    k = ConvertCharactorToKey(parts[1][0]);
                }

                Modifiers m;
                if (!ModifiersHelper.TryParse(parts[0], out m))
                {
                    return(false);
                }

                result = new ModifiedKey(m, k);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Produces a human readable representation of the hot key info.
        /// Static version because sometimes we have these two pieces of information
        /// separately, not as an object.
        /// </summary>
        /// <param name="modifiers">The key modifiers.</param>
        /// <param name="key">The keycode.</param>
        /// <returns>String rep using CSAW for Control, Shift, Alt and Win modifiers.</returns>
        public static string ToString(Modifiers modifiers, Keys key)
        {
            var result = ModifiersHelper.ToString(modifiers) + "-" + key.ToString();

            return(result);
        }