Struct sdl2::keyboard::KeyboardState
source · pub struct KeyboardState<'a> { /* private fields */ }
Implementations§
source§impl<'a> KeyboardState<'a>
impl<'a> KeyboardState<'a>
pub fn new(_e: &'a EventPump) -> KeyboardState<'a>
sourcepub fn is_scancode_pressed(&self, scancode: Scancode) -> bool
pub fn is_scancode_pressed(&self, scancode: Scancode) -> bool
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)
}
sourcepub fn scancodes(&self) -> ScancodeIterator<'_> ⓘ
pub fn scancodes(&self) -> ScancodeIterator<'_> ⓘ
Returns an iterator all scancodes with a boolean indicating if the scancode is pressed.
sourcepub fn pressed_scancodes(&self) -> PressedScancodeIterator<'_> ⓘ
pub fn pressed_scancodes(&self) -> PressedScancodeIterator<'_> ⓘ
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> Freeze for KeyboardState<'a>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more