Module ruscii::keyboard

source ·
Expand description

Keyboard

The keyboard module contains all implementation-related details of keyboard I/O and the key event interface.

Example

Most applications will interact with the key event interface through its State object.

Pressed and Released events can be retrieved by use of the Keyboard::last_key_events function while held-down keys can be obtained by the Keyboard::get_keys_down function. These can then be pattern-matched to find the type of key as in the following example:

let mut app = App::new();

app.run(|app_state: &mut State, window: &mut Window| {
    for key_event in app_state.keyboard().last_key_events() {
        match key_event {
            KeyEvent::Pressed(Key::Esc) => app_state.stop(),
            KeyEvent::Pressed(Key::Q) => app_state.stop(),
            _ => (),
        }
    }

    for key_down in app_state.keyboard().get_keys_down() {
        match key_down {
            Key::W => state.left_player.direction = -1,
            Key::S => state.left_player.direction = 1,
            Key::O => state.right_player.direction = -1,
            Key::L => state.right_player.direction = 1,
            _ => (),
        }
    }
});

Structs

  • An object representing the state of the keyboard.

Enums

  • The keys detectable by ruscii.
  • Events that are detected for each key.