public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var items = new List <DeviceObjectItem>(); if (device == null) { return(items.ToArray()); } var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List <Guid> typeGuids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List <string> typeName = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.ObjectId.Flags).ThenBy(x => x.ObjectId.InstanceNumber).ToArray(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, OffsetType = device.Information.Type, Aspect = o.Aspect, Flags = o.ObjectId.Flags, Instance = o.ObjectId.InstanceNumber, Type = o.ObjectType, }; items.Add(item); } return(items.ToArray()); }
/// <summary>Return axis setting value if axis exists.</summary> static string GetAxisValue(List <DeviceObjectItem> objects, bool invert, Guid type, bool removeIfFound, params string[] names) { DeviceObjectItem o = null; // Try to find by name. foreach (var name in names) { // Try exact match first. o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && string.Compare(x.Name, name, true) == 0); if (o == null) { o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && x.Name.Contains(name)); } if (o != null) { if (removeIfFound) { objects.Remove(o); } break; } } // Try to find by type. if (o == null) { o = objects.FirstOrDefault(x => x.Type == type); } return(o == null ? "" : string.Format("{0}{1}", (invert ? "-" : "") + SettingName.SType.Axis // Use X360CE axis index. , o.DiIndex + 1)); }
public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List <Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List <string> names = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray(); var items = new List <DeviceObjectItem>(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, Instance = o.ObjectId.InstanceNumber, Usage = o.Usage, Aspect = o.Aspect, Flags = o.ObjectId.Flags, GuidValue = o.ObjectType, GuidName = guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(), }; items.Add(item); } return(items.ToArray()); }
/// <summary>Return button setting value if button exists.</summary> static string GetButtonValue(List <DeviceObjectItem> objects, int instance, bool removeIfFound, params string[] names) { DeviceObjectItem o = null; // Try to find by name. foreach (var name in names) { // Try exact match first. o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && string.Compare(x.Name, name, true) == 0); if (o == null) { o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && x.Name.Contains(name)); } if (o != null) { if (removeIfFound) { objects.Remove(o); } break; } } // Try to find by instance. if (o == null) { o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && x.Instance == instance); } // Use instance number which is same as X360CE button index. return(o == null ? "" : string.Format("{0}{1}", SettingName.SType.Button, o.DiIndex + 1)); }
public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List<string> names = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray(); var items = new List<DeviceObjectItem>(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, Instance = o.ObjectId.InstanceNumber, Usage = o.Usage, Aspect = o.Aspect, Flags = o.ObjectId.Flags, GuidValue = o.ObjectType, GuidName = guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(), }; items.Add(item); } return items.ToArray(); }
/// <summary>Return button setting value if button exists.</summary> static string GetButtonValue(List <DeviceObjectItem> objects, int?dIndex, bool removeIfFound, params string[] names) { DeviceObjectItem o = null; // Try to find by name. var rxs = names.Select(x => new Regex(x, RegexOptions.IgnoreCase)); foreach (var rx in rxs) { // Try find a match. o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && rx.IsMatch(x.Name)); if (o != null) { if (removeIfFound) { objects.Remove(o); } break; } } // Try to find by Custom DIndex. if (o == null && dIndex.HasValue) { o = objects.FirstOrDefault(x => (x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key) && x.DiIndex == dIndex.Value); } // Use instance number which is same as X360CE button index. return(o == null ? "" : string.Format("{0}{1}", SettingName.SType.Button, o.DiIndex + 1)); }
public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var items = new List <DeviceObjectItem>(); if (device == null) { return(items.ToArray()); } var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List <Guid> typeGuids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List <string> typeName = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.ObjectId.Flags).ThenBy(x => x.ObjectId.InstanceNumber).ToArray(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, Aspect = o.Aspect, Flags = o.ObjectId.Flags, ObjectId = (int)o.ObjectId, Instance = o.ObjectId.InstanceNumber, Type = o.ObjectType, DiIndex = o.ObjectId.InstanceNumber - 1, }; items.Add(item); } // Update Button DIndexes. var buttons = items.Where(x => x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key).OrderBy(x => x.Instance).ToArray(); for (int i = 0; i < buttons.Length; i++) { buttons[i].DiIndex = i; } return(items.ToArray()); }
public static DeviceObjectItem[] GetDeviceObjects(Joystick device) { var items = new List <DeviceObjectItem>(); if (device == null) { return(items.ToArray()); } var og = typeof(SharpDX.DirectInput.ObjectGuid); var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid)); List <Guid> typeGuids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList(); List <string> typeName = guidFileds.Select(x => x.Name).ToList(); var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.ObjectId.Flags).ThenBy(x => x.ObjectId.InstanceNumber).ToArray(); foreach (var o in objects) { var item = new DeviceObjectItem() { Name = o.Name, Offset = o.Offset, Aspect = o.Aspect, Flags = o.ObjectId.Flags, ObjectId = (int)o.ObjectId, Instance = o.ObjectId.InstanceNumber, Type = o.ObjectType, DiIndex = o.ObjectId.InstanceNumber - 1, }; var isAxis = o.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.Axis); isAxis |= o.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.AbsoluteAxis); isAxis |= o.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.RelativeAxis); if (isAxis) { try { var p = device.GetObjectPropertiesById(o.ObjectId); if (p != null) { item.DeadZone = p.DeadZone; item.Granularity = p.Granularity; item.LogicalRangeMin = p.LogicalRange.Minimum; item.LogicalRangeMax = p.LogicalRange.Maximum; item.PhysicalRangeMin = p.PhysicalRange.Minimum; item.PhysicalRangeMax = p.PhysicalRange.Maximum; item.RangeMin = p.Range.Minimum; item.RangeMax = p.Range.Maximum; item.Saturation = p.Saturation; } } catch (Exception ex) { _ = ex.Message; } } items.Add(item); } // Update Button DIndexes. var buttons = items.Where(x => x.Type == ObjectGuid.Button || x.Type == ObjectGuid.Key).OrderBy(x => x.Instance).ToArray(); for (int i = 0; i < buttons.Length; i++) { buttons[i].DiIndex = i; } return(items.ToArray()); }