[][src]Module localghost::keyboard

Browser keyboard API

MDN Documentation

Examples

use localghost::dom::{self, Element};
use localghost::prelude::*;
use localghost::keyboard::Keyboard;

use async_std::stream::StreamExt;

#[localghost::main]
async fn main() {
    let keyboard = Keyboard::new();
    let body = dom::body();

    let desc = Element::with_text("p", "Press a key, get a key name");
    body.append(desc);

    let heading = Element::new("h1");
    heading.set_attr("id", "target");
    body.append(heading);

    // For every keyboard event modify the heading.
    let mut keydown = keyboard.key_down();
    while let Some(ev) = keydown.next().await {
        let el = dom::query_selector("#target").unwrap_throw();
        el.set_text(&ev.key().to_string());
    };
}

Structs

KeyDownStream

A stream capturing keydown events.

KeyUpStream

A stream capturing keyup events.

Keyboard

Browser keyboard API.

KeyboardEvent

An event that describes a user interaction with the keyboard.

Enums

KeyKind

The computed key value of a KeyboardEvent

ModifierKey

Special keys which are used to generate special characters or cause special actions when used in combination with other keys.