pub struct KeyboardState<'a> { /* private fields */ }

Implementations

Returns true if the scancode is pressed.

Example
use sdl2::keyboard::Scancode;

fn is_a_pressed(e: &sdl2::EventPump) -> bool {
    e.keyboard_state().is_scancode_pressed(Scancode::A)
}

Returns an iterator all scancodes with a boolean indicating if the scancode is pressed.

Returns an iterator of pressed scancodes.

Example
use sdl2::keyboard::Keycode;
use sdl2::keyboard::Scancode;
use std::collections::HashSet;

fn pressed_scancode_set(e: &sdl2::EventPump) -> HashSet<Scancode> {
    e.keyboard_state().pressed_scancodes().collect()
}

fn pressed_keycode_set(e: &sdl2::EventPump) -> HashSet<Keycode> {
    e.keyboard_state().pressed_scancodes()
        .filter_map(Keycode::from_scancode)
        .collect()
}

fn newly_pressed(old: &HashSet<Scancode>, new: &HashSet<Scancode>) -> HashSet<Scancode> {
    new - old
    // sugar for: new.difference(old).collect()
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.