get_keystroke

Function get_keystroke 

Source
pub fn get_keystroke(
    user_index: impl TryInto<u32>,
    _reserved: (),
) -> Result<Option<Keystroke>, Error>
Expand description

[microsoft.com] XInputGetKeystroke (1.3+)

Retrieves gamepad input events.

§Argumen.t

  • user_index — The controller to get button/keystrokes for (0 .. xuser::MAX_COUNT or xuser::INDEX_ANY.)
  • _reserved — Reserved for future use, simply pass ().

§Example

// Wait for any gamepad button
let gamepad = 0;
loop {
    match xinput::get_keystroke(gamepad, ()) {
        Ok(Some(keystroke)) => break println!("{keystroke:#?}"),
        Ok(None)            => std::thread::yield_now(), // wait
        Err(err)            => break println!("no xinput or no gamepad: {err:?}"),
    }
}

§Output

Keystroke {
    virtual_key: VK::PadStart,
    unicode: 0,
    flags: Keystroke::KeyDown,
    user_index: 0,
    hid_code: 0,
}

§Errors