pub struct XInputState {
    pub raw: XINPUT_STATE,
}
Expand description

This wraps an XINPUT_STATE value and provides a more rusty (read-only) interface to the data it contains.

All three major game companies use different names for most of the buttons, so the docs for each button method list out what each of the major companies call that button. To the driver it’s all the same, it’s just however you want to think of them.

If sequential calls to xinput_get_state for a given controller slot have the same packet number then the controller state has not changed since the last call. The PartialEq and Eq implementations for this wrapper type reflect that. The exact value of the packet number is unimportant.

If you want to do something that the rust wrapper doesn’t support, just use the raw field to get at the inner value.

Fields§

§raw: XINPUT_STATE

The raw value we’re wrapping.

Implementations§

source§

impl XInputState

source

pub fn north_button(&self) -> bool

The north button of the action button group.

  • Nintendo: X
  • Playstation: Triangle
  • XBox: Y
source

pub fn south_button(&self) -> bool

The south button of the action button group.

  • Nintendo: B
  • Playstation: X
  • XBox: A
source

pub fn east_button(&self) -> bool

The east button of the action button group.

  • Nintendo: A
  • Playstation: Circle
  • XBox: B
source

pub fn west_button(&self) -> bool

The west button of the action button group.

  • Nintendo: Y
  • Playstation: Square
  • XBox: X
source

pub fn arrow_up(&self) -> bool

The up button on the directional pad.

source

pub fn arrow_down(&self) -> bool

The down button on the directional pad.

source

pub fn arrow_left(&self) -> bool

The left button on the directional pad.

source

pub fn arrow_right(&self) -> bool

The right button on the directional pad.

source

pub fn start_button(&self) -> bool

The “start” button.

  • Nintendo: Start (NES / SNES), ‘+’ (Pro Controller)
  • Playstation: Start
  • XBox: Start
source

pub fn select_button(&self) -> bool

The “not start” button.

  • Nintendo: Select (NES / NES), ‘-’ (Pro Controller)
  • Playstation: Select
  • XBox: Back
source

pub fn guide_button(&self) -> bool

The “guide” button.

  • Nintendo: Home
  • Playstation: PS
  • XBox: Guide
source

pub fn left_shoulder(&self) -> bool

The upper left shoulder button.

  • Nintendo: L
  • Playstation: L1
  • XBox: LB
source

pub fn right_shoulder(&self) -> bool

The upper right shoulder button.

  • Nintendo: R
  • Playstation: R1
  • XBox: RB
source

pub const TRIGGER_THRESHOLD: u8 = 30u8

The default threshold to count a trigger as being “pressed”.

source

pub fn left_trigger(&self) -> u8

The lower left shoulder trigger. If you want to use this as a simple boolean it is suggested that you compare it to the TRIGGER_THRESHOLD constant.

  • Nintendo: ZL
  • Playstation: L2
  • XBox: LT
source

pub fn right_trigger(&self) -> u8

The lower right shoulder trigger. If you want to use this as a simple boolean it is suggested that you compare it to the TRIGGER_THRESHOLD constant.

  • Nintendo: ZR
  • Playstation: R2
  • XBox: RT
source

pub fn left_trigger_bool(&self) -> bool

The lower left shoulder trigger as a bool using the default threshold.

  • Nintendo: ZL
  • Playstation: L2
  • XBox: LT
source

pub fn right_trigger_bool(&self) -> bool

The lower right shoulder trigger as a bool using the default threshold.

  • Nintendo: ZR
  • Playstation: R2
  • XBox: RT
source

pub fn left_thumb_button(&self) -> bool

The left thumb stick being pressed inward.

  • Nintendo: (L)
  • Playstation: L3
  • XBox: (L)
source

pub fn right_thumb_button(&self) -> bool

The right thumb stick being pressed inward.

  • Nintendo: (R)
  • Playstation: R3
  • XBox: (R)
source

pub const LEFT_STICK_DEADZONE: i16 = 7_849i16

The suggested default deadzone for use with the left thumb stick.

source

pub const RIGHT_STICK_DEADZONE: i16 = 8_689i16

The suggested default deadzone for use with the right thumb stick.

source

pub fn left_stick_raw(&self) -> (i16, i16)

The left stick raw value.

Positive values are to the right (X-axis) or up (Y-axis).

source

pub fn right_stick_raw(&self) -> (i16, i16)

The right stick raw value.

Positive values are to the right (X-axis) or up (Y-axis).

source

pub fn left_stick_normalized(&self) -> (f32, f32)

The left stick value normalized with the default dead-zone.

See normalize_raw_stick_value for more.

source

pub fn right_stick_normalized(&self) -> (f32, f32)

The right stick value normalized with the default dead-zone.

See normalize_raw_stick_value for more.

source

pub fn normalize_raw_stick_value( raw_stick: (i16, i16), deadzone: i16 ) -> (f32, f32)

This helper normalizes a raw stick value using the given deadzone.

If the raw value’s 2d length is less than the deadzone the result will be (0.0,0.0), otherwise the result is normalized across the range from the deadzone point to the maximum value.

The deadzone value is clamped to the range 0 to 32,766 (inclusive) before use. Negative inputs or maximum value inputs make the normalization just work improperly.

Trait Implementations§

source§

impl Clone for XInputState

source§

fn clone(&self) -> XInputState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for XInputState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for XInputState

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for XInputState

source§

fn eq(&self, other: &XInputState) -> bool

Equality for XInputState values is based only on the dwPacketNumber of the wrapped XINPUT_STATE value. This is entirely correct for values obtained from the xinput system, but if you make your own XInputState values for some reason you can confuse it.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for XInputState

source§

impl Eq for XInputState

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.