Example #1
0
        /// <summary>
        ///  Converts keyboard shortcut into its user friendly string representation.
        /// </summary>
        /// <param name="keys">Keys pressed by user.</param>
        /// <returns>User friendly string representation of the keyboard shortcut, including modifiers.</returns>
        public static string ToString(Keys keys)
        {
            if ((keys & ~Keys.ShiftKey & ~Keys.ControlKey & ~Keys.Menu &
                 ~Keys.Shift & ~Keys.Control & ~Keys.Alt) == Keys.None)
            {
                //do not capture if modifiers keys are pressed on their own
                return(null);
            }

            string modifierKeysString = KeysStringConverter.ModifierKeysToString(ref keys);

            if (modifierKeysString == string.Empty)
            {
                //do not accept keys pressed without a modifier
                return(null);
            }

            string keyName = keys.ToString();

            return(modifierKeysString + keyName);
        }
Example #2
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteValue(KeysStringConverter.ToString((Keys)value));
 }
Example #3
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(KeysStringConverter.FromString(reader.Value as string));
 }