Crate keyboard_codes

Crate keyboard_codes 

Source
Expand description

keyboard-codes: Cross-platform keyboard key code mapping and conversion

This crate provides comprehensive keyboard key definitions and cross-platform code mapping for Windows, Linux, and macOS. It supports standard keys, modifiers, custom key mapping, and bidirectional conversion between key names and platform-specific codes.

§Examples

use keyboard_codes::{Key, Modifier, Platform, KeyCodeMapper};

// Parse key from string
let key: Key = "Enter".parse().unwrap();
assert_eq!(key, Key::Enter);

// Convert key to platform-specific code
let windows_code = key.to_code(Platform::Windows);
let linux_code = key.to_code(Platform::Linux);

// Parse key from code
let key_from_code = Key::from_code(0x0D, Platform::Windows).unwrap();
assert_eq!(key_from_code, Key::Enter);

§Features

  • serde: Enables serialization/deserialization support
  • phf: Uses perfect hash functions for faster lookups

Re-exports§

pub use error::KeyParseError;
pub use mapping::custom::CustomKey;
pub use mapping::custom::CustomKeyMap;
pub use types::Key;
pub use types::KeyCodeMapper;
pub use types::Modifier;
pub use types::Platform;

Modules§

error
Error types for key parsing and mapping operations
mapping
Key code mapping implementations Key code mapping implementations
types
Core type definitions for keyboard keys and platforms Core type definitions for keyboard keys and platforms
utils
Utility functions and helpers Utility functions and helpers

Functions§

current_platform
Get the current platform based on compilation target