[][src]Struct sdl2::keyboard::KeyboardState

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

Methods

impl<'a> KeyboardState<'a>[src]

pub fn new(_e: &'a EventPump) -> KeyboardState<'a>[src]

pub fn is_scancode_pressed(&self, scancode: Scancode) -> bool[src]

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)
}

pub fn scancodes(&self) -> ScancodeIterator[src]

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

pub fn pressed_scancodes(&self) -> PressedScancodeIterator[src]

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

impl<'a> RefUnwindSafe for KeyboardState<'a>

impl<'a> Send for KeyboardState<'a>

impl<'a> Sync for KeyboardState<'a>

impl<'a> Unpin for KeyboardState<'a>

impl<'a> UnwindSafe for KeyboardState<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.