/// <summary> /// Returns the index of the button that is to be checked within the controller's mapping configuration. /// </summary> /// <param name="button">The requested button whose index is to be obtained.</param> /// <param name="buttonMappings">The button mapping for the specified controller.</param> /// <returns></returns> public static int DInputGetMappedButtonIndex(ControllerButtonsGeneric button, ButtonMapping buttonMappings) { // Stores the button that is to be checked. int buttonToTest = ButtonNull; // Switch statement checks the mapping of each button to the virtual xbox button. switch (button) { case ControllerButtonsGeneric.ButtonA: buttonToTest = buttonMappings.ButtonA; break; case ControllerButtonsGeneric.ButtonB: buttonToTest = buttonMappings.ButtonB; break; case ControllerButtonsGeneric.ButtonX: buttonToTest = buttonMappings.ButtonX; break; case ControllerButtonsGeneric.ButtonY: buttonToTest = buttonMappings.ButtonY; break; case ControllerButtonsGeneric.ButtonLb: buttonToTest = buttonMappings.ButtonLb; break; case ControllerButtonsGeneric.ButtonRb: buttonToTest = buttonMappings.ButtonRb; break; case ControllerButtonsGeneric.ButtonLs: buttonToTest = buttonMappings.ButtonLs; break; case ControllerButtonsGeneric.ButtonRs: buttonToTest = buttonMappings.ButtonRs; break; case ControllerButtonsGeneric.ButtonBack: buttonToTest = buttonMappings.ButtonBack; break; case ControllerButtonsGeneric.ButtonStart: buttonToTest = buttonMappings.ButtonStart; break; case ControllerButtonsGeneric.ButtonGuide: buttonToTest = buttonMappings.ButtonGuide; break; } // Return the button that is to be checked. return(buttonToTest); }
/// <summary> /// Retrieves whether a specific button is pressed or not. /// Accepts an enum of Controller_Buttons_Generic as parameter and returns the button ID mapped to /// the requested Controller_Buttons_Generic member of the "emulated" 360 pad. /// True if said button is pressed, else false. /// </summary> public bool GetButtonState(ControllerButtonsGeneric button) { // Retrieve requested button index. int buttonIndex = DInputGetMappedButtonIndex(button, InputMappings.ButtonMapping); // Return the state declaring if the joystick button is pressed. return(buttonIndex != 255 && JoystickState.Buttons[buttonIndex]); }