keyboard-codes 0.2.0

Cross-platform keyboard key code mapping and conversion
Documentation
use std::fmt;

/// Keyboard modifier key enumeration
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Modifier {
    /// Alt key (generic)
    Alt,
    /// Ctrl key (generic)
    Control,
    /// Shift key (generic)
    Shift,
    /// System key (Windows key/Command key)
    Meta,
    /// Left Alt key
    LeftAlt,
    /// Right Alt key
    RightAlt,
    /// Left Ctrl key
    LeftControl,
    /// Right Ctrl key
    RightControl,
    /// Left Shift key
    LeftShift,
    /// Right Shift key
    RightShift,
    /// Left system key
    LeftMeta,
    /// Right system key
    RightMeta,
}

impl Modifier {
    /// Get the string representation of the modifier
    pub fn as_str(&self) -> &'static str {
        match self {
            Modifier::Alt => "Alt",
            Modifier::Control => "Control",
            Modifier::Shift => "Shift",
            Modifier::Meta => "Meta",
            Modifier::LeftAlt => "LeftAlt",
            Modifier::RightAlt => "RightAlt",
            Modifier::LeftControl => "LeftControl",
            Modifier::RightControl => "RightControl",
            Modifier::LeftShift => "LeftShift",
            Modifier::RightShift => "RightShift",
            Modifier::LeftMeta => "LeftMeta",
            Modifier::RightMeta => "RightMeta",
        }
    }
}

impl fmt::Display for Modifier {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_str())
    }
}