Crates.io | keysymdefs |
lib.rs | keysymdefs |
version | 0.2.0 |
source | src |
created_at | 2023-11-11 19:03:22.277308 |
updated_at | 2023-11-13 15:59:00.631206 |
description | A collection of key symbol definitions. |
homepage | https://github.com/milchinskiy/keysymdefs |
repository | https://github.com/milchinskiy/keysymdefs.git |
max_upload_size | |
id | 1032281 |
size | 656,791 |
This crate provides a mapping from the keysym code to a string representation of the keysym and vice versa.
cargo add keysymdefs
pub struct Item {
name: &str,
cleared_name: &str,
keysym: u32,
unicode: Option<u32>,
desc: &str,
}
use keysymdefs::get_item_by_keysym;
fn get_item_by_keysym(keysym: u32) -> Option<&Item>
// e.g.
if let Some(key) = get_item_by_keysym(keys::XF86XK_AudioPlay) {
println!("{}", key.keysym()); // 269025044
println!("{}", key.name()); // XF86XK_AudioPlay
println!("{}", key.cleared_name()); // AudioPlay
println!("{}", key.desc()); // Start playing of audio
println!("{}", key.unicode()); // None
println!("{}", key.unicode_char()); // None
assert_eq!(keys::XF86XK_AudioPlay, 269025044);
}
fn get_item_by_name(name: &str) -> Option<&Item>
truncated canonical name, no "XK_" or "XF86XK_" prefixes and "_" in the middle
fn get_item_by_cleared_name(name: &str) -> Option<&Item>
!WARN!: Please note that not all keys have a unicode value
fn get_item_by_unicode(unicode: u32) -> Option<&Item>
use keysymdefs::{keys, get_item_by_keysym};
println!("Keysym: {:x}", keys::XF86XK_AudioPlay); // `0x1008ff14`
let item = get_item_by_keysym(keys::XF86XK_AudioPlay).unwrap();
println!("{}", item.name()); // `XF86XK_AudioPlay`
println!("{}", item.cleared_name()); // `AudioPlay`