/// <summary> /// Creates a new <see cref="Gamepad"/> instance from an xinput state structure. /// </summary> /// <param name="index">The controller number. Can be in the range of 0 to 3.</param> /// <param name="state">The current state of the gamepad.</param> private Gamepad(XInput.State state, XInput.UserIndex index) { this.LeftThumbDeadzone = XInput.Gamepad.LeftThumbDeadzone / (double)thumbMaxValue; this.RightThumbDeadzone = XInput.Gamepad.RightThumbDeadzone / (double)thumbMaxValue; this.LeftTriggerThreshold = XInput.Gamepad.TriggerThreshold / (double)triggerMaxValue; this.RightTriggerThreshold = XInput.Gamepad.TriggerThreshold / (double)triggerMaxValue; this.UserIndex = (int)index; this.StartObserverThread(); }
/// <summary> /// Collects all the connected xinput gamepads. /// </summary> /// <returns>A list of all connected devices.</returns> public static List <Gamepad> GetConnectedDevices() { List <Gamepad> gamepads = new List <Gamepad>(); for (XInput.UserIndex userIndex = 0; userIndex < XInput.UserIndex.MaxCount; userIndex++) { XInput.State state = new XInput.State(); XInput.Error result = XInput.GetState(userIndex, out state); if (result == XInput.Error.Success) { gamepads.Add(new Gamepad(state, userIndex)); } } return(gamepads); }