public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var input = new CycInput(); var str = value.ToString().ToLower(); var mouseStart = str.IndexOf(mouseStr); var keyStart = str.IndexOf(keyStr); if (mouseStart >= 0) { var mouseEnd = mouseStart + mouseStr.Length; var mouseSubStr = GetSubStr(str, mouseEnd); var mouseSubStrs = mouseSubStr.Split(','); var mouseAll = EnumHelpers.GetAll <MouseButton>(); foreach (var subStr in mouseSubStrs) { var trimStr = subStr.Trim(); if (trimStr.Length == 1 && char.IsDigit(trimStr[0])) { input.ClickCount = int.Parse(trimStr); } try { input.MouseButton = mouseAll.First(mb => trimStr == mb.ToString().ToLower()); } catch (InvalidOperationException) { }//no matched mouse button } } if (keyStart >= 0) // if key specified { input.InputKeys = new CycKeyCollection(); var keyEnd = keyStart + keyStr.Length; var keySubStr = GetSubStr(str, keyEnd); var keySubStrs = keySubStr.Split(','); var keyAll = EnumHelpers.GetAll <Key>(); foreach (var subStr in keySubStrs) { var trimStr = subStr.Trim(); var keys = keyAll.Where(key => trimStr == key.ToString().ToLower()); foreach (var key in keys) { input.InputKeys.Add(new CycKey(key)); } } } return(input); }
public static void SetInput(DependencyObject obj, CycInput value) => obj.SetValue(InputProperty, value);