keyboard_codes/types/
modifier.rs

1use std::fmt;
2
3/// Keyboard modifier key enumeration
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum Modifier {
7    /// Alt key (generic)
8    Alt,
9    /// Ctrl key (generic)
10    Control,
11    /// Shift key (generic)
12    Shift,
13    /// System key (Windows key/Command key)
14    Meta,
15    /// Left Alt key
16    LeftAlt,
17    /// Right Alt key
18    RightAlt,
19    /// Left Ctrl key
20    LeftControl,
21    /// Right Ctrl key
22    RightControl,
23    /// Left Shift key
24    LeftShift,
25    /// Right Shift key
26    RightShift,
27    /// Left system key
28    LeftMeta,
29    /// Right system key
30    RightMeta,
31}
32
33impl Modifier {
34    /// Get the string representation of the modifier
35    pub fn as_str(&self) -> &'static str {
36        match self {
37            Modifier::Alt => "Alt",
38            Modifier::Control => "Control",
39            Modifier::Shift => "Shift",
40            Modifier::Meta => "Meta",
41            Modifier::LeftAlt => "LeftAlt",
42            Modifier::RightAlt => "RightAlt",
43            Modifier::LeftControl => "LeftControl",
44            Modifier::RightControl => "RightControl",
45            Modifier::LeftShift => "LeftShift",
46            Modifier::RightShift => "RightShift",
47            Modifier::LeftMeta => "LeftMeta",
48            Modifier::RightMeta => "RightMeta",
49        }
50    }
51}
52
53impl fmt::Display for Modifier {
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        write!(f, "{}", self.as_str())
56    }
57}