keysymdefs

Crates.iokeysymdefs
lib.rskeysymdefs
version0.2.0
sourcesrc
created_at2023-11-11 19:03:22.277308
updated_at2023-11-13 15:59:00.631206
descriptionA collection of key symbol definitions.
homepagehttps://github.com/milchinskiy/keysymdefs
repositoryhttps://github.com/milchinskiy/keysymdefs.git
max_upload_size
id1032281
size656,791
Alexander Milchinskiy (milchinskiy)

documentation

https://github.com/milchinskiy/keysymdefs

README

Keysymdefs

This crate provides a mapping from the keysym code to a string representation of the keysym and vice versa.

Installation

cargo add keysymdefs

Record Item

pub struct Item {
    name: &str,
    cleared_name: &str,
    keysym: u32,
    unicode: Option<u32>,
    desc: &str,
}

Get Record by KeySym

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);
}

Get Record by canonical name

fn get_item_by_name(name: &str) -> Option<&Item>

Get Record by cleared name

truncated canonical name, no "XK_" or "XF86XK_" prefixes and "_" in the middle

fn get_item_by_cleared_name(name: &str) -> Option<&Item>

Get Record by unicode

!WARN!: Please note that not all keys have a unicode value

fn get_item_by_unicode(unicode: u32) -> Option<&Item>

Module keysymdefs::keys

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`
Commit count: 6

cargo fmt