public GameControllerDirectInput(InputSourceWindowsDirectInput source, DirectInput directInput, DeviceInstance instance) { Source = source; Name = instance.InstanceName.TrimEnd('\0'); Id = instance.InstanceGuid; ProductId = instance.ProductGuid; joystick = new DirectInputJoystick(directInput, instance.InstanceGuid); var objects = joystick.GetObjects(); int sliderCount = 0; foreach (var obj in objects) { var objectId = obj.ObjectId; string objectName = obj.Name.TrimEnd('\0'); GameControllerObjectInfo objectInfo = null; if (objectId.HasAnyFlag(DeviceObjectTypeFlags.Button | DeviceObjectTypeFlags.PushButton | DeviceObjectTypeFlags.ToggleButton)) { var buttonInfo = new GameControllerButtonInfo(); buttonInfo.Type = objectId.HasFlags(DeviceObjectTypeFlags.ToggleButton) ? GameControllerButtonType.ToggleButton : GameControllerButtonType.PushButton; objectInfo = buttonInfo; buttonInfos.Add(buttonInfo); } else if (objectId.HasAnyFlag(DeviceObjectTypeFlags.Axis | DeviceObjectTypeFlags.AbsoluteAxis | DeviceObjectTypeFlags.RelativeAxis)) { var axis = new DirectInputAxisInfo(); if (!GuidToAxisOffsets.TryGetValue(obj.ObjectType, out axis.Offset)) { // Axis that should not be used, since it does not map to a valid object guid continue; } // All objects after x/y/z and x/y/z rotation are sliders if (obj.ObjectType == ObjectGuid.Slider) { axis.Offset += sliderCount++; } objectInfo = axis; axisInfos.Add(axis); } else if (objectId.HasFlags(DeviceObjectTypeFlags.PointOfViewController)) { var directionInfo = new GameControllerDirectionInfo(); objectInfo = directionInfo; directionInfos.Add(directionInfo); } if (objectInfo != null) { objectInfo.Name = objectName; } } // Sort axes, buttons and hats do not need to be sorted axisInfos.Sort((a, b) => a.Offset.CompareTo(b.Offset)); InitializeButtonStates(); }
public GamePadDirectInput(InputSourceWindowsDirectInput source, InputManager inputManager, GameControllerDirectInput controller, GamePadLayout layout) : base(inputManager, controller, layout) { this.controller = controller; Source = source; Name = controller.Name; Id = controller.Id; ProductId = controller.ProductId; }