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_COUNTorxuser::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
- error::BAD_ARGUMENTS - Invalid
user_index(expected0 .. xuser::MAX_COUNTorxuser::INDEX_ANY) - error::DEVICE_NOT_CONNECTED - No gamepad connected for
user_index. error::EMPTY- NoKeystrokes available. ReturnsOk(None)instead.- error::INVALID_FUNCTION - API unavailable: requires XInput 1.3 or later