Skip to main content

pc_remote/input/
key.rs

1use crate::prelude::*;
2use enigo::Key as EnigoKey;
3
4// The keyboard key codes
5#[derive(Hash, Debug, Display, Clone, Eq, PartialEq, Serialize, Deserialize)]
6pub enum Key {
7    // Modifiers:
8    Ctrl,
9    Shift,
10    Alt,
11    Super,
12
13    // Characters:
14    A,
15    B,
16    C,
17    D,
18    E,
19    F,
20    G,
21    H,
22    I,
23    J,
24    K,
25    L,
26    M,
27    N,
28    O,
29    P,
30    Q,
31    R,
32    S,
33    T,
34    U,
35    V,
36    W,
37    X,
38    Y,
39    Z,
40
41    // Functions:
42    F1,
43    F2,
44    F3,
45    F4,
46    F5,
47    F6,
48    F7,
49    F8,
50    F9,
51    F10,
52    F11,
53    F12,
54
55    // Digitals:
56    D0,
57    D1,
58    D2,
59    D3,
60    D4,
61    D5,
62    D6,
63    D7,
64    D8,
65    D9,
66
67    // NumPad:
68    N0,
69    N1,
70    N2,
71    N3,
72    N4,
73    N5,
74    N6,
75    N7,
76    N8,
77    N9,
78
79    // Symbols:
80    Plus,
81    Minus,
82    Equal,
83    Star,
84    Slash,
85    Backslash,
86
87    // Special keys:
88    Esc,
89    Tab,
90    CapsLock,
91    NumLock,
92    Space,
93    Enter,
94    Backspace,
95    Delete,
96
97    // Arrows:
98    Left,
99    Right,
100    Up,
101    Down,
102
103    // Media:
104    PlayPause,
105    Prev,
106    Next,
107    Stop,
108    VolumeUp,
109    VolumeDown,
110    Mute,
111}
112
113impl ::std::convert::Into<EnigoKey> for Key {
114    fn into(self) -> EnigoKey {
115        match self {
116            // Modifiers:
117            Self::Ctrl => EnigoKey::Control,
118            Self::Shift => EnigoKey::Shift,
119            Self::Alt => EnigoKey::Alt,
120            Self::Super => EnigoKey::Meta,
121
122            // Characters:
123            Self::A => EnigoKey::Unicode('A'),
124            Self::B => EnigoKey::Unicode('B'),
125            Self::C => EnigoKey::Unicode('C'),
126            Self::D => EnigoKey::Unicode('D'),
127            Self::E => EnigoKey::Unicode('E'),
128            Self::F => EnigoKey::Unicode('F'),
129            Self::G => EnigoKey::Unicode('G'),
130            Self::H => EnigoKey::Unicode('H'),
131            Self::I => EnigoKey::Unicode('I'),
132            Self::J => EnigoKey::Unicode('J'),
133            Self::K => EnigoKey::Unicode('K'),
134            Self::L => EnigoKey::Unicode('L'),
135            Self::M => EnigoKey::Unicode('M'),
136            Self::N => EnigoKey::Unicode('N'),
137            Self::O => EnigoKey::Unicode('O'),
138            Self::P => EnigoKey::Unicode('P'),
139            Self::Q => EnigoKey::Unicode('Q'),
140            Self::R => EnigoKey::Unicode('R'),
141            Self::S => EnigoKey::Unicode('S'),
142            Self::T => EnigoKey::Unicode('T'),
143            Self::U => EnigoKey::Unicode('U'),
144            Self::V => EnigoKey::Unicode('V'),
145            Self::W => EnigoKey::Unicode('W'),
146            Self::X => EnigoKey::Unicode('X'),
147            Self::Y => EnigoKey::Unicode('Y'),
148            Self::Z => EnigoKey::Unicode('Z'),
149
150            // Functions:
151            Self::F1 => EnigoKey::F1,
152            Self::F2 => EnigoKey::F2,
153            Self::F3 => EnigoKey::F3,
154            Self::F4 => EnigoKey::F4,
155            Self::F5 => EnigoKey::F5,
156            Self::F6 => EnigoKey::F6,
157            Self::F7 => EnigoKey::F7,
158            Self::F8 => EnigoKey::F8,
159            Self::F9 => EnigoKey::F9,
160            Self::F10 => EnigoKey::F10,
161            Self::F11 => EnigoKey::F11,
162            Self::F12 => EnigoKey::F12,
163
164            // Digitals:
165            Self::D0 => EnigoKey::Other(0),
166            Self::D1 => EnigoKey::Other(1),
167            Self::D2 => EnigoKey::Other(2),
168            Self::D3 => EnigoKey::Other(3),
169            Self::D4 => EnigoKey::Other(4),
170            Self::D5 => EnigoKey::Other(5),
171            Self::D6 => EnigoKey::Other(6),
172            Self::D7 => EnigoKey::Other(7),
173            Self::D8 => EnigoKey::Other(8),
174            Self::D9 => EnigoKey::Other(9),
175
176            // NumPad:
177            Self::N0 => EnigoKey::Numpad0,
178            Self::N1 => EnigoKey::Numpad1,
179            Self::N2 => EnigoKey::Numpad2,
180            Self::N3 => EnigoKey::Numpad3,
181            Self::N4 => EnigoKey::Numpad4,
182            Self::N5 => EnigoKey::Numpad5,
183            Self::N6 => EnigoKey::Numpad6,
184            Self::N7 => EnigoKey::Numpad7,
185            Self::N8 => EnigoKey::Numpad8,
186            Self::N9 => EnigoKey::Numpad9,
187
188            // Symbols:
189            Self::Plus => EnigoKey::Unicode('+'),
190            Self::Minus => EnigoKey::Unicode('-'),
191            Self::Equal => EnigoKey::Unicode('='),
192            Self::Star => EnigoKey::Unicode('*'),
193            Self::Slash => EnigoKey::Unicode('/'),
194            Self::Backslash => EnigoKey::Unicode('\\'),
195
196            // Special keys:
197            Self::Esc => EnigoKey::Escape,
198            Self::Tab => EnigoKey::Tab,
199            Self::CapsLock => EnigoKey::CapsLock,
200            Self::NumLock => EnigoKey::Numlock,
201            Self::Space => EnigoKey::Space,
202            Self::Enter => EnigoKey::Return,
203            Self::Backspace => EnigoKey::Backspace,
204            Self::Delete => EnigoKey::Delete,
205
206            // Arrows:
207            Self::Left => EnigoKey::LeftArrow,
208            Self::Right => EnigoKey::RightArrow,
209            Self::Up => EnigoKey::UpArrow,
210            Self::Down => EnigoKey::DownArrow,
211
212            // Media:
213            Self::PlayPause => EnigoKey::MediaPlayPause,
214            Self::Prev => EnigoKey::MediaPrevTrack,
215            Self::Next => EnigoKey::MediaNextTrack,
216            Self::Stop => EnigoKey::MediaStop,
217            Self::VolumeUp => EnigoKey::VolumeUp,
218            Self::VolumeDown => EnigoKey::VolumeDown,
219            Self::Mute => EnigoKey::VolumeMute,
220        }
221    }
222}