public XboxController() { // Initialize Buttons Buttons = new XboxButton[14]; Buttons[0] = new XboxButton(OnButtonAPressed, OnButtonAReleased); Buttons[1] = new XboxButton(OnButtonBPressed, OnButtonBReleased); Buttons[2] = new XboxButton(OnButtonXPressed, OnButtonXReleased); Buttons[3] = new XboxButton(OnButtonYPressed, OnButtonYReleased); Buttons[4] = new XboxButton(OnButtonStartPressed, OnButtonStartReleased); Buttons[5] = new XboxButton(OnButtonBackPressed, OnButtonBackReleased); Buttons[6] = new XboxButton(OnButtonLeftShoulderPressed, OnButtonLeftShoulderReleased); Buttons[7] = new XboxButton(OnButtonRightShoulderPressed, OnButtonRightShoulderReleased); Buttons[8] = new XboxButton(OnThumbStickLeftPressed, OnThumbStickLeftReleased); Buttons[9] = new XboxButton(OnThumbStickRightPressed, OnThumbStickRightReleased); Buttons[10] = new XboxButton(OnDPadUpPressed, OnDPadUpReleased); Buttons[11] = new XboxButton(OnDPadDownPressed, OnDPadDownReleased); Buttons[12] = new XboxButton(OnDPadLeftPressed, OnDPadLeftReleased); Buttons[13] = new XboxButton(OnDPadRightPressed, OnDPadRightReleased); // Initialize Triggers Triggers = new XboxTrigger[2]; Triggers[0] = new XboxTrigger(OnTriggerLeftChanged); Triggers[1] = new XboxTrigger(OnTriggerRightChanged); // Initialize ThumbSticks ThumbSticks = new XboxThumbStick[2]; ThumbSticks[0] = new XboxThumbStick(OnThumbStickLeftChanged); ThumbSticks[1] = new XboxThumbStick(OnThumbStickRightChanged); Thread t = new Thread(x => { while (true) Listen(); }); t.Start(); }
/// <summary> /// Checks if the button has been released, returning true if it has, false otherwise. /// </summary> private bool CheckButtonReleased(ButtonState state, XboxButton button) { if (button == null) return false; if (state == ButtonState.Released && button.State == ButtonState.Pressed) { //button = new Tuple<ButtonState, ChangedEventHandler, ChangedEventHandler>(state, button.Item2, button.Item3); button.State = state; return true; } return false; }