How to add keyboard events in Rust Webassembly?

Example - keydown

This example creates a keydown event using the EventListener Struct and bind it with a HTML textarea element. Whenever a key is entered with the keyboard on the textarea, the keyboard event type and key is set as the text content of a paragraph element.

pub fn eventlistener_keyboardevent_keydown(){
    let window = web_sys::window().expect("global window does not exists");    
    let document = window.document().expect("expecting a document on window");

    let text_area = document.get_element_by_id("text_area")

    let message = document.get_element_by_id("message")

    let on_keydown = EventListener::new(&text_area, "keydown", move |event| {

    let keyboard_event = event.clone()

            let mut event_string = String::from("");
            event_string.push_str(&" : ");


Source Code