This directory contains examples demonstrating various features and use cases of the keymap-rs library. Each example showcases different aspects of key mapping, from basic usage to advanced configurations.
Note
All examples below work with any backend by simply passing the backend feature (e.g., crossterm, termion, wasm) to the --features argument.
cargo run --example {example} --features {backend}
Basic key mapping without derive macros
Illustrates how to use the library without the #[derive(KeyMap)] macro, including manual TOML configuration parsing and basic action handling.
Using the KeyMap derive macro
Presents the most common and recommended approach using the #[derive(KeyMap)] macro, showcasing automatic keymap generation from enum attributes and clean, declarative key mapping.
External configuration with Config
Shows how to load key mappings exclusively from external configuration files, ignoring derive macro definitions, and highlights file-based key overrides and custom key descriptions.
Merging derive macros with external config using DerivedConfig
Explores combining derive macro defaults with external configuration overrides, covering configuration precedence and key group patterns like @digit.
Multi-mode application with different key mappings
Illustrates building applications with multiple modes (like vim), where different key mappings are active depending on the current mode, including mode-based key mapping switching and dynamic mode transitions.
Key sequences and timing
Explains how to handle multi-key sequences (like j j for double-tap actions), including sequence detection, timing-based handling, and sequence timeout management.
Complete WebAssembly game implementation
A fully functional browser-based game demonstrating keymap-rs in WebAssembly.
Try it live: https://rezigned.com/keymap-rs/
The WASM example requires additional setup:
cd examples/wasm
# Install trunk for WASM building
cargo install trunk
# Build and serve the WASM example
trunk serve
# Or build for production
trunk build --releaseThen open your browser to http://localhost:8080 to play the game.