Giter VIP home page Giter VIP logo

wasm-keys's Introduction

wasm-keys

This crate delivers compile-time static type bindings for key values in web-sys::KeyboardEvent.

use wasm_keys::WasmKey;

fn SomeComponent() {
    let pressed_keys: Vec<WasmKey> = vec![];
    
    let keydown_listener = wasm_bindgen::closure::Closure::wrap(
        Box::new(move |event: web_sys::KeyboardEvent| { 
            pressed_keys.push(WasmKey::from(event.key()));
        }) as Box<dyn Fn(_)>);
}

Typing

At its core, this crate introduces the WasmKey enum, written to reflect every key value listed in the MDN KeyboardEvent documentation. In addition, this crate provides a direct mapping from KeyboardEvent.key() to WasmKey upon compile-time.

Hotkeys

This crate offers a feature to build a Hotkey, a type that consists of one or many WasmKeys. Specific modifier keys are noted as such.

Hotkey implements the Eq trait, allowing nice deep equality checks:

use wasm_keys::{WasmKey, Hotkey};

fn compare(hotkey: Hotkey, keys: Vec<WasmKey>) -> bool {
    hotkey == Hotkey::from_keys(keys);
}

References

Usages

leptos-hotkeys - a hotkey library for Leptos, a web framework written in Rust.

wasm-keys's People

Contributors

friendlymatthew avatar

Watchers

Álvaro Mondéjar Rubio avatar

wasm-keys's Issues

CI

Similar to Leptos hotkeys, we'd probably want a CI for checks + formatting and a cargo release workflow

@mondeja any other thoughts?

The purpose of this crate is to be thoroughly tested, which means when #1 gets done, maybe we can find a keyboard fuzzer repo that we can constantly pull from and use that to test the newest changes?

Create fuzz testing crate for key presses

@mondeja what do you think?

The goal is to split leptos-hotkeys and use this library for types. This crate implements the From trait for web_sys::Keyboard_Event. It also does the Hotkey creation here.

Will add you as a maintainer to this as well

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.