Skip to main content

ferroui_remote_protocol/input/
physical_key.rs

1// Generated from the upstream enum definition; do not reorder: the numeric
2// values are part of the contract with platform backends.
3
4use std::fmt;
5use std::str::FromStr;
6
7/// Represents a keyboard physical key.
8/// 
9/// The names follow the W3C codes, see <https://www.w3.org/TR/uievents-code/>.
10#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
11#[repr(i32)]
12pub enum PhysicalKey {
13    /// Represents no key.
14    #[default]
15    None = 0,
16    /// ``~` on a US keyboard.
17    /// This is the `半角/全角/漢字` (hankaku/zenkaku/kanji) key on Japanese keyboards.
18    Backquote = 1,
19    /// Used for both the US `\|` (on the 101-key layout) and also for the key located between the `"` and
20    /// `Enter` keys on row C of the 102-, 104- and 106-key layouts.
21    /// `#~` on a UK (102) keyboard.
22    Backslash = 2,
23    /// `[{` on a US keyboard.
24    BracketLeft = 3,
25    /// `]}` on a US keyboard.
26    BracketRight = 4,
27    /// `,&lt;` on a US keyboard.
28    Comma = 5,
29    /// `0)` on a US keyboard.
30    Digit0 = 6,
31    /// `1!` on a US keyboard.
32    Digit1 = 7,
33    /// `2@` on a US keyboard.
34    Digit2 = 8,
35    /// `3#` on a US keyboard.
36    Digit3 = 9,
37    /// `4$` on a US keyboard.
38    Digit4 = 10,
39    /// `5%` on a US keyboard.
40    Digit5 = 11,
41    /// `6^` on a US keyboard.
42    Digit6 = 12,
43    /// `7&amp;` on a US keyboard.
44    Digit7 = 13,
45    /// `8*` on a US keyboard.
46    Digit8 = 14,
47    /// `9(` on a US keyboard.
48    Digit9 = 15,
49    /// `=+` on a US keyboard.
50    Equal = 16,
51    /// Located between the left `Shift` and `Z` keys.
52    /// `\|` on a UK keyboard.
53    IntlBackslash = 17,
54    /// Located between the `/` and right `Shift` keys.
55    /// `\ろ` (ro) on a Japanese keyboard.
56    IntlRo = 18,
57    /// Located between the `=` and `Backspace` keys.
58    /// `¥` (yen) on a Japanese keyboard.
59    /// `\/` on a Russian keyboard.
60    IntlYen = 19,
61    /// `a` on a US keyboard.
62    /// `q` on an AZERTY (e.g., French) keyboard.
63    A = 20,
64    /// `b` on a US keyboard.
65    B = 21,
66    /// `c` on a US keyboard.
67    C = 22,
68    /// `d` on a US keyboard.
69    D = 23,
70    /// `e` on a US keyboard.
71    E = 24,
72    /// `f` on a US keyboard.
73    F = 25,
74    /// `g` on a US keyboard.
75    G = 26,
76    /// `h` on a US keyboard.
77    H = 27,
78    /// `i` on a US keyboard.
79    I = 28,
80    /// `j` on a US keyboard.
81    J = 29,
82    /// `k` on a US keyboard.
83    K = 30,
84    /// `l` on a US keyboard.
85    L = 31,
86    /// `m` on a US keyboard.
87    M = 32,
88    /// `n` on a US keyboard.
89    N = 33,
90    /// `o` on a US keyboard.
91    O = 34,
92    /// `p` on a US keyboard.
93    P = 35,
94    /// `q` on a US keyboard.
95    /// `a` on an AZERTY (e.g., French) keyboard.
96    Q = 36,
97    /// `r` on a US keyboard.
98    R = 37,
99    /// `s` on a US keyboard.
100    S = 38,
101    /// `t` on a US keyboard.
102    T = 39,
103    /// `u` on a US keyboard.
104    U = 40,
105    /// `v` on a US keyboard.
106    V = 41,
107    /// `w` on a US keyboard.
108    /// `z` on an AZERTY (e.g., French) keyboard.
109    W = 42,
110    /// `x` on a US keyboard.
111    X = 43,
112    /// `y` on a US keyboard.
113    /// `z` on a QWERTZ (e.g., German) keyboard.
114    Y = 44,
115    /// `z` on a US keyboard.
116    /// `w` on an AZERTY (e.g., French) keyboard.
117    /// `y` on a QWERTZ (e.g., German) keyboard.
118    Z = 45,
119    /// `-_` on a US keyboard.
120    Minus = 46,
121    /// `.&gt;` on a US keyboard.
122    Period = 47,
123    /// `'"` on a US keyboard.
124    Quote = 48,
125    /// `;:` on a US keyboard.
126    Semicolon = 49,
127    /// `/?` on a US keyboard.
128    Slash = 50,
129    /// `Alt`, `Option` or `⌥`.
130    AltLeft = 51,
131    /// `Alt`, `Option` or `⌥`.
132    /// This is labelled `AltGr` key on many keyboard layouts.
133    AltRight = 52,
134    /// `Backspace` or `⌫`.
135    /// Labelled `Delete` on Apple keyboards.
136    Backspace = 53,
137    /// `CapsLock` or `⇪`.
138    CapsLock = 54,
139    /// The application context menu key, which is typically found between the right `Meta` key
140    /// and the right `Control` key.
141    ContextMenu = 55,
142    /// `Control` or `⌃`.
143    ControlLeft = 56,
144    /// `Control` or `⌃`.
145    ControlRight = 57,
146    /// `Enter` or `↵`.
147    /// Labelled `Return` on Apple keyboards.
148    Enter = 58,
149    /// The `⊞` (Windows), `⌘`, `Command` or other OS symbol key.
150    MetaLeft = 59,
151    /// The `⊞` (Windows), `⌘`, `Command` or other OS symbol key.
152    MetaRight = 60,
153    /// `Shift` or `⇧`.
154    ShiftLeft = 61,
155    /// `Shift` or `⇧`.
156    ShiftRight = 62,
157    /// ` ` (space).
158    Space = 63,
159    /// `Tab` or `⇥`.
160    Tab = 64,
161    /// Japanese: `変換` (henkan).
162    Convert = 65,
163    /// Japanese: `カタカナ/ひらがな/ローマ字` (katakana/hiragana/romaji).
164    KanaMode = 66,
165    /// Korean: HangulMode `한/영` (han/yeong).
166    /// Japanese (Mac keyboard): `かな` (kana).
167    Lang1 = 67,
168    /// Korean: Hanja `한자` (hanja).
169    /// Japanese (Mac keyboard): `英数` (eisu).
170    Lang2 = 68,
171    /// Japanese (word-processing keyboard): Katakana.
172    Lang3 = 69,
173    /// Japanese (word-processing keyboard): Hiragana.
174    Lang4 = 70,
175    /// Japanese (word-processing keyboard): Zenkaku/Hankaku.
176    Lang5 = 71,
177    /// Japanese: `無変換` (muhenkan).
178    NonConvert = 72,
179    /// `⌦`. The forward delete key.
180    /// Note that on Apple keyboards, the key labelled `Delete` on the main part of the keyboard is
181    /// `Backspace`.
182    Delete = 73,
183    /// `End` or `↘`.
184    End = 74,
185    /// `Help`.
186    /// Not present on standard PC keyboards.
187    Help = 75,
188    /// `Home` or `↖`.
189    Home = 76,
190    /// `Insert` or `Ins`.
191    /// Not present on Apple keyboards.
192    Insert = 77,
193    /// `Page Down`, `PgDn` or `⇟`.
194    PageDown = 78,
195    /// `Page Up`, `PgUp` or `⇞`.
196    PageUp = 79,
197    /// `↓`.
198    ArrowDown = 80,
199    /// `←`.
200    ArrowLeft = 81,
201    /// `→`.
202    ArrowRight = 82,
203    /// `↑`.
204    ArrowUp = 83,
205    /// Numeric keypad `Num Lock`.
206    /// On the Mac, this is used for the numpad `Clear` key.
207    NumLock = 84,
208    /// Numeric keypad `0 Ins` on a keyboard.
209    /// `0` on a phone or remote control.
210    NumPad0 = 85,
211    /// Numeric keypad `1 End` on a keyboard.
212    /// `1` or `1 QZ` on a phone or remote control.
213    NumPad1 = 86,
214    /// Numeric keypad `2 ↓` on a keyboard.
215    /// `2 ABC` on a phone or remote control.
216    NumPad2 = 87,
217    /// Numeric keypad `3 PgDn` on a keyboard.
218    /// `3 DEF` on a phone or remote control.
219    NumPad3 = 88,
220    /// Numeric keypad `4 ←` on a keyboard.
221    /// `4 GHI` on a phone or remote control.
222    NumPad4 = 89,
223    /// Numeric keypad `5` on a keyboard.
224    /// `5 JKL` on a phone or remote control.
225    NumPad5 = 90,
226    /// Numeric keypad `6 →` on a keyboard.
227    /// `6 MNO` on a phone or remote control.
228    NumPad6 = 91,
229    /// Numeric keypad `7 Home` on a keyboard.
230    /// `7 PQRS` or `7 PRS` on a phone or remote control.
231    NumPad7 = 92,
232    /// Numeric keypad `8 ↑` on a keyboard.
233    /// `8 TUV` on a phone or remote control.
234    NumPad8 = 93,
235    /// Numeric keypad `9 PgUp` on a keyboard.
236    /// `9 WXYZ` or `9 WXY` on a phone or remote control.
237    NumPad9 = 94,
238    /// Numeric keypad `+`.
239    NumPadAdd = 95,
240    /// Numeric keypad `C` or `AC` (All Clear).
241    /// Also for use with numpads that have a `Clear` key that is separate from the `NumLock` key.
242    /// On the Mac, the numpad `Clear` key is `NumLock`.
243    NumPadClear = 96,
244    /// Numeric keypad `,` (thousands separator).
245    /// For locales where the thousands separator is a "." (e.g., Brazil), this key may generate a `.`.
246    NumPadComma = 97,
247    /// Numeric keypad `. Del`.
248    /// For locales where the decimal separator is "," (e.g., Brazil), this key may generate a `,`.
249    NumPadDecimal = 98,
250    /// Numeric keypad `/`.
251    NumPadDivide = 99,
252    /// Numeric keypad `Enter`.
253    NumPadEnter = 100,
254    /// Numeric keypad `=`.
255    NumPadEqual = 101,
256    /// Numeric keypad `*` on a keyboard.
257    /// For use with numpads that provide mathematical operations (`+`, `-`, `*` and `/`).
258    NumPadMultiply = 102,
259    /// Numeric keypad `(`.
260    /// Found on the Microsoft Natural Keyboard.
261    NumPadParenLeft = 103,
262    /// Numeric keypad `)`.
263    /// Found on the Microsoft Natural Keyboard.
264    NumPadParenRight = 104,
265    /// Numeric keypad `-`.
266    NumPadSubtract = 105,
267    /// `Esc` or `⎋`.
268    Escape = 106,
269    /// `F1`.
270    F1 = 107,
271    /// `F2`.
272    F2 = 108,
273    /// `F3`.
274    F3 = 109,
275    /// `F4`.
276    F4 = 110,
277    /// `F5`.
278    F5 = 111,
279    /// `F6`.
280    F6 = 112,
281    /// `F7`.
282    F7 = 113,
283    /// `F8`.
284    F8 = 114,
285    /// `F9`.
286    F9 = 115,
287    /// `F10`.
288    F10 = 116,
289    /// `F11`.
290    F11 = 117,
291    /// `F12`.
292    F12 = 118,
293    /// `F13`.
294    F13 = 119,
295    /// `F14`.
296    F14 = 120,
297    /// `F15`.
298    F15 = 121,
299    /// `F16`.
300    F16 = 122,
301    /// `F17`.
302    F17 = 123,
303    /// `F18`.
304    F18 = 124,
305    /// `F19`.
306    F19 = 125,
307    /// `F20`.
308    F20 = 126,
309    /// `F21`.
310    F21 = 127,
311    /// `F22`.
312    F22 = 128,
313    /// `F23`.
314    F23 = 129,
315    /// `F24`.
316    F24 = 130,
317    /// `PrtScr SysRq` or `Print Screen`.
318    PrintScreen = 131,
319    /// `Scroll Lock`.
320    ScrollLock = 132,
321    /// `Pause Break`.
322    Pause = 133,
323    /// Browser `Back`.
324    /// Some laptops place this key to the left of the `↑` key.
325    BrowserBack = 134,
326    /// Browser `Favorites`.
327    BrowserFavorites = 135,
328    /// Browser `Forward`.
329    /// Some laptops place this key to the right of the `↑` key.
330    BrowserForward = 136,
331    /// Browser `Home`.
332    BrowserHome = 137,
333    /// Browser `Refresh`.
334    BrowserRefresh = 138,
335    /// Browser `Search`.
336    BrowserSearch = 139,
337    /// Browser `Stop`.
338    BrowserStop = 140,
339    /// `Eject` or `⏏`.
340    /// This key is placed in the function section on some Apple keyboards.
341    Eject = 141,
342    /// `App 1`.
343    /// Sometimes labelled `My Computer` on the keyboard.
344    LaunchApp1 = 142,
345    /// `App 2`.
346    /// Sometimes labelled `Calculator` on the keyboard.
347    LaunchApp2 = 143,
348    /// `Mail`.
349    LaunchMail = 144,
350    /// Media `Play/Pause` or `⏵⏸`.
351    MediaPlayPause = 145,
352    /// Media `Select`.
353    MediaSelect = 146,
354    /// Media `Stop` or `⏹`.
355    MediaStop = 147,
356    /// Media `Next` or `⏭`.
357    MediaTrackNext = 148,
358    /// Media `Previous` or `⏮`.
359    MediaTrackPrevious = 149,
360    /// `Power`.
361    Power = 150,
362    /// `Sleep`.
363    Sleep = 151,
364    /// `Volume Down`.
365    AudioVolumeDown = 152,
366    /// `Mute`.
367    AudioVolumeMute = 153,
368    /// `Volume Up`.
369    AudioVolumeUp = 154,
370    /// `Wake Up`.
371    WakeUp = 155,
372    /// `Again`.
373    /// Legacy.
374    /// Found on Sun’s USB keyboard.
375    Again = 156,
376    /// `Copy`.
377    /// Legacy.
378    /// Found on Sun’s USB keyboard.
379    Copy = 157,
380    /// `Cut`.
381    /// Legacy.
382    /// Found on Sun’s USB keyboard.
383    Cut = 158,
384    /// `Find`.
385    /// Legacy.
386    /// Found on Sun’s USB keyboard.
387    Find = 159,
388    /// `Open`.
389    /// Legacy.
390    /// Found on Sun’s USB keyboard.
391    Open = 160,
392    /// `Paste`.
393    /// Legacy.
394    /// Found on Sun’s USB keyboard.
395    Paste = 161,
396    /// `Props`.
397    /// Legacy.
398    /// Found on Sun’s USB keyboard.
399    Props = 162,
400    /// `Select`.
401    /// Legacy.
402    /// Found on Sun’s USB keyboard.
403    Select = 163,
404    /// `Undo`.
405    /// Legacy.
406    /// Found on Sun’s USB keyboard.
407    Undo = 164,
408}
409
410/// The error returned when a string does not name a [`PhysicalKey`].
411#[derive(Clone, Debug, PartialEq, Eq)]
412pub struct ParsePhysicalKeyError(pub String);
413
414impl fmt::Display for ParsePhysicalKeyError {
415    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
416        write!(f, "Requested value '{}' was not found.", self.0)
417    }
418}
419
420impl std::error::Error for ParsePhysicalKeyError {}
421
422/// Every name of the enumeration, including aliases, with its value.
423static NAMES: &[(&str, PhysicalKey)] = &[
424    ("None", PhysicalKey::None),
425    ("Backquote", PhysicalKey::Backquote),
426    ("Backslash", PhysicalKey::Backslash),
427    ("BracketLeft", PhysicalKey::BracketLeft),
428    ("BracketRight", PhysicalKey::BracketRight),
429    ("Comma", PhysicalKey::Comma),
430    ("Digit0", PhysicalKey::Digit0),
431    ("Digit1", PhysicalKey::Digit1),
432    ("Digit2", PhysicalKey::Digit2),
433    ("Digit3", PhysicalKey::Digit3),
434    ("Digit4", PhysicalKey::Digit4),
435    ("Digit5", PhysicalKey::Digit5),
436    ("Digit6", PhysicalKey::Digit6),
437    ("Digit7", PhysicalKey::Digit7),
438    ("Digit8", PhysicalKey::Digit8),
439    ("Digit9", PhysicalKey::Digit9),
440    ("Equal", PhysicalKey::Equal),
441    ("IntlBackslash", PhysicalKey::IntlBackslash),
442    ("IntlRo", PhysicalKey::IntlRo),
443    ("IntlYen", PhysicalKey::IntlYen),
444    ("A", PhysicalKey::A),
445    ("B", PhysicalKey::B),
446    ("C", PhysicalKey::C),
447    ("D", PhysicalKey::D),
448    ("E", PhysicalKey::E),
449    ("F", PhysicalKey::F),
450    ("G", PhysicalKey::G),
451    ("H", PhysicalKey::H),
452    ("I", PhysicalKey::I),
453    ("J", PhysicalKey::J),
454    ("K", PhysicalKey::K),
455    ("L", PhysicalKey::L),
456    ("M", PhysicalKey::M),
457    ("N", PhysicalKey::N),
458    ("O", PhysicalKey::O),
459    ("P", PhysicalKey::P),
460    ("Q", PhysicalKey::Q),
461    ("R", PhysicalKey::R),
462    ("S", PhysicalKey::S),
463    ("T", PhysicalKey::T),
464    ("U", PhysicalKey::U),
465    ("V", PhysicalKey::V),
466    ("W", PhysicalKey::W),
467    ("X", PhysicalKey::X),
468    ("Y", PhysicalKey::Y),
469    ("Z", PhysicalKey::Z),
470    ("Minus", PhysicalKey::Minus),
471    ("Period", PhysicalKey::Period),
472    ("Quote", PhysicalKey::Quote),
473    ("Semicolon", PhysicalKey::Semicolon),
474    ("Slash", PhysicalKey::Slash),
475    ("AltLeft", PhysicalKey::AltLeft),
476    ("AltRight", PhysicalKey::AltRight),
477    ("Backspace", PhysicalKey::Backspace),
478    ("CapsLock", PhysicalKey::CapsLock),
479    ("ContextMenu", PhysicalKey::ContextMenu),
480    ("ControlLeft", PhysicalKey::ControlLeft),
481    ("ControlRight", PhysicalKey::ControlRight),
482    ("Enter", PhysicalKey::Enter),
483    ("MetaLeft", PhysicalKey::MetaLeft),
484    ("MetaRight", PhysicalKey::MetaRight),
485    ("ShiftLeft", PhysicalKey::ShiftLeft),
486    ("ShiftRight", PhysicalKey::ShiftRight),
487    ("Space", PhysicalKey::Space),
488    ("Tab", PhysicalKey::Tab),
489    ("Convert", PhysicalKey::Convert),
490    ("KanaMode", PhysicalKey::KanaMode),
491    ("Lang1", PhysicalKey::Lang1),
492    ("Lang2", PhysicalKey::Lang2),
493    ("Lang3", PhysicalKey::Lang3),
494    ("Lang4", PhysicalKey::Lang4),
495    ("Lang5", PhysicalKey::Lang5),
496    ("NonConvert", PhysicalKey::NonConvert),
497    ("Delete", PhysicalKey::Delete),
498    ("End", PhysicalKey::End),
499    ("Help", PhysicalKey::Help),
500    ("Home", PhysicalKey::Home),
501    ("Insert", PhysicalKey::Insert),
502    ("PageDown", PhysicalKey::PageDown),
503    ("PageUp", PhysicalKey::PageUp),
504    ("ArrowDown", PhysicalKey::ArrowDown),
505    ("ArrowLeft", PhysicalKey::ArrowLeft),
506    ("ArrowRight", PhysicalKey::ArrowRight),
507    ("ArrowUp", PhysicalKey::ArrowUp),
508    ("NumLock", PhysicalKey::NumLock),
509    ("NumPad0", PhysicalKey::NumPad0),
510    ("NumPad1", PhysicalKey::NumPad1),
511    ("NumPad2", PhysicalKey::NumPad2),
512    ("NumPad3", PhysicalKey::NumPad3),
513    ("NumPad4", PhysicalKey::NumPad4),
514    ("NumPad5", PhysicalKey::NumPad5),
515    ("NumPad6", PhysicalKey::NumPad6),
516    ("NumPad7", PhysicalKey::NumPad7),
517    ("NumPad8", PhysicalKey::NumPad8),
518    ("NumPad9", PhysicalKey::NumPad9),
519    ("NumPadAdd", PhysicalKey::NumPadAdd),
520    ("NumPadClear", PhysicalKey::NumPadClear),
521    ("NumPadComma", PhysicalKey::NumPadComma),
522    ("NumPadDecimal", PhysicalKey::NumPadDecimal),
523    ("NumPadDivide", PhysicalKey::NumPadDivide),
524    ("NumPadEnter", PhysicalKey::NumPadEnter),
525    ("NumPadEqual", PhysicalKey::NumPadEqual),
526    ("NumPadMultiply", PhysicalKey::NumPadMultiply),
527    ("NumPadParenLeft", PhysicalKey::NumPadParenLeft),
528    ("NumPadParenRight", PhysicalKey::NumPadParenRight),
529    ("NumPadSubtract", PhysicalKey::NumPadSubtract),
530    ("Escape", PhysicalKey::Escape),
531    ("F1", PhysicalKey::F1),
532    ("F2", PhysicalKey::F2),
533    ("F3", PhysicalKey::F3),
534    ("F4", PhysicalKey::F4),
535    ("F5", PhysicalKey::F5),
536    ("F6", PhysicalKey::F6),
537    ("F7", PhysicalKey::F7),
538    ("F8", PhysicalKey::F8),
539    ("F9", PhysicalKey::F9),
540    ("F10", PhysicalKey::F10),
541    ("F11", PhysicalKey::F11),
542    ("F12", PhysicalKey::F12),
543    ("F13", PhysicalKey::F13),
544    ("F14", PhysicalKey::F14),
545    ("F15", PhysicalKey::F15),
546    ("F16", PhysicalKey::F16),
547    ("F17", PhysicalKey::F17),
548    ("F18", PhysicalKey::F18),
549    ("F19", PhysicalKey::F19),
550    ("F20", PhysicalKey::F20),
551    ("F21", PhysicalKey::F21),
552    ("F22", PhysicalKey::F22),
553    ("F23", PhysicalKey::F23),
554    ("F24", PhysicalKey::F24),
555    ("PrintScreen", PhysicalKey::PrintScreen),
556    ("ScrollLock", PhysicalKey::ScrollLock),
557    ("Pause", PhysicalKey::Pause),
558    ("BrowserBack", PhysicalKey::BrowserBack),
559    ("BrowserFavorites", PhysicalKey::BrowserFavorites),
560    ("BrowserForward", PhysicalKey::BrowserForward),
561    ("BrowserHome", PhysicalKey::BrowserHome),
562    ("BrowserRefresh", PhysicalKey::BrowserRefresh),
563    ("BrowserSearch", PhysicalKey::BrowserSearch),
564    ("BrowserStop", PhysicalKey::BrowserStop),
565    ("Eject", PhysicalKey::Eject),
566    ("LaunchApp1", PhysicalKey::LaunchApp1),
567    ("LaunchApp2", PhysicalKey::LaunchApp2),
568    ("LaunchMail", PhysicalKey::LaunchMail),
569    ("MediaPlayPause", PhysicalKey::MediaPlayPause),
570    ("MediaSelect", PhysicalKey::MediaSelect),
571    ("MediaStop", PhysicalKey::MediaStop),
572    ("MediaTrackNext", PhysicalKey::MediaTrackNext),
573    ("MediaTrackPrevious", PhysicalKey::MediaTrackPrevious),
574    ("Power", PhysicalKey::Power),
575    ("Sleep", PhysicalKey::Sleep),
576    ("AudioVolumeDown", PhysicalKey::AudioVolumeDown),
577    ("AudioVolumeMute", PhysicalKey::AudioVolumeMute),
578    ("AudioVolumeUp", PhysicalKey::AudioVolumeUp),
579    ("WakeUp", PhysicalKey::WakeUp),
580    ("Again", PhysicalKey::Again),
581    ("Copy", PhysicalKey::Copy),
582    ("Cut", PhysicalKey::Cut),
583    ("Find", PhysicalKey::Find),
584    ("Open", PhysicalKey::Open),
585    ("Paste", PhysicalKey::Paste),
586    ("Props", PhysicalKey::Props),
587    ("Select", PhysicalKey::Select),
588    ("Undo", PhysicalKey::Undo),
589];
590
591#[allow(non_upper_case_globals)]
592impl PhysicalKey {
593    /// The numeric value of the member.
594    #[inline]
595    pub const fn value(self) -> i32 {
596        self as i32
597    }
598
599    /// The member with the given numeric value, if one is defined.
600    pub fn from_value(value: i32) -> Option<PhysicalKey> {
601        NAMES.iter().map(|(_, k)| *k).find(|k| *k as i32 == value)
602    }
603
604    /// The name of the member. For values with several names this is the
605    /// first one declared.
606    pub fn name(self) -> &'static str {
607        match self {
608            PhysicalKey::None => "None",
609            PhysicalKey::Backquote => "Backquote",
610            PhysicalKey::Backslash => "Backslash",
611            PhysicalKey::BracketLeft => "BracketLeft",
612            PhysicalKey::BracketRight => "BracketRight",
613            PhysicalKey::Comma => "Comma",
614            PhysicalKey::Digit0 => "Digit0",
615            PhysicalKey::Digit1 => "Digit1",
616            PhysicalKey::Digit2 => "Digit2",
617            PhysicalKey::Digit3 => "Digit3",
618            PhysicalKey::Digit4 => "Digit4",
619            PhysicalKey::Digit5 => "Digit5",
620            PhysicalKey::Digit6 => "Digit6",
621            PhysicalKey::Digit7 => "Digit7",
622            PhysicalKey::Digit8 => "Digit8",
623            PhysicalKey::Digit9 => "Digit9",
624            PhysicalKey::Equal => "Equal",
625            PhysicalKey::IntlBackslash => "IntlBackslash",
626            PhysicalKey::IntlRo => "IntlRo",
627            PhysicalKey::IntlYen => "IntlYen",
628            PhysicalKey::A => "A",
629            PhysicalKey::B => "B",
630            PhysicalKey::C => "C",
631            PhysicalKey::D => "D",
632            PhysicalKey::E => "E",
633            PhysicalKey::F => "F",
634            PhysicalKey::G => "G",
635            PhysicalKey::H => "H",
636            PhysicalKey::I => "I",
637            PhysicalKey::J => "J",
638            PhysicalKey::K => "K",
639            PhysicalKey::L => "L",
640            PhysicalKey::M => "M",
641            PhysicalKey::N => "N",
642            PhysicalKey::O => "O",
643            PhysicalKey::P => "P",
644            PhysicalKey::Q => "Q",
645            PhysicalKey::R => "R",
646            PhysicalKey::S => "S",
647            PhysicalKey::T => "T",
648            PhysicalKey::U => "U",
649            PhysicalKey::V => "V",
650            PhysicalKey::W => "W",
651            PhysicalKey::X => "X",
652            PhysicalKey::Y => "Y",
653            PhysicalKey::Z => "Z",
654            PhysicalKey::Minus => "Minus",
655            PhysicalKey::Period => "Period",
656            PhysicalKey::Quote => "Quote",
657            PhysicalKey::Semicolon => "Semicolon",
658            PhysicalKey::Slash => "Slash",
659            PhysicalKey::AltLeft => "AltLeft",
660            PhysicalKey::AltRight => "AltRight",
661            PhysicalKey::Backspace => "Backspace",
662            PhysicalKey::CapsLock => "CapsLock",
663            PhysicalKey::ContextMenu => "ContextMenu",
664            PhysicalKey::ControlLeft => "ControlLeft",
665            PhysicalKey::ControlRight => "ControlRight",
666            PhysicalKey::Enter => "Enter",
667            PhysicalKey::MetaLeft => "MetaLeft",
668            PhysicalKey::MetaRight => "MetaRight",
669            PhysicalKey::ShiftLeft => "ShiftLeft",
670            PhysicalKey::ShiftRight => "ShiftRight",
671            PhysicalKey::Space => "Space",
672            PhysicalKey::Tab => "Tab",
673            PhysicalKey::Convert => "Convert",
674            PhysicalKey::KanaMode => "KanaMode",
675            PhysicalKey::Lang1 => "Lang1",
676            PhysicalKey::Lang2 => "Lang2",
677            PhysicalKey::Lang3 => "Lang3",
678            PhysicalKey::Lang4 => "Lang4",
679            PhysicalKey::Lang5 => "Lang5",
680            PhysicalKey::NonConvert => "NonConvert",
681            PhysicalKey::Delete => "Delete",
682            PhysicalKey::End => "End",
683            PhysicalKey::Help => "Help",
684            PhysicalKey::Home => "Home",
685            PhysicalKey::Insert => "Insert",
686            PhysicalKey::PageDown => "PageDown",
687            PhysicalKey::PageUp => "PageUp",
688            PhysicalKey::ArrowDown => "ArrowDown",
689            PhysicalKey::ArrowLeft => "ArrowLeft",
690            PhysicalKey::ArrowRight => "ArrowRight",
691            PhysicalKey::ArrowUp => "ArrowUp",
692            PhysicalKey::NumLock => "NumLock",
693            PhysicalKey::NumPad0 => "NumPad0",
694            PhysicalKey::NumPad1 => "NumPad1",
695            PhysicalKey::NumPad2 => "NumPad2",
696            PhysicalKey::NumPad3 => "NumPad3",
697            PhysicalKey::NumPad4 => "NumPad4",
698            PhysicalKey::NumPad5 => "NumPad5",
699            PhysicalKey::NumPad6 => "NumPad6",
700            PhysicalKey::NumPad7 => "NumPad7",
701            PhysicalKey::NumPad8 => "NumPad8",
702            PhysicalKey::NumPad9 => "NumPad9",
703            PhysicalKey::NumPadAdd => "NumPadAdd",
704            PhysicalKey::NumPadClear => "NumPadClear",
705            PhysicalKey::NumPadComma => "NumPadComma",
706            PhysicalKey::NumPadDecimal => "NumPadDecimal",
707            PhysicalKey::NumPadDivide => "NumPadDivide",
708            PhysicalKey::NumPadEnter => "NumPadEnter",
709            PhysicalKey::NumPadEqual => "NumPadEqual",
710            PhysicalKey::NumPadMultiply => "NumPadMultiply",
711            PhysicalKey::NumPadParenLeft => "NumPadParenLeft",
712            PhysicalKey::NumPadParenRight => "NumPadParenRight",
713            PhysicalKey::NumPadSubtract => "NumPadSubtract",
714            PhysicalKey::Escape => "Escape",
715            PhysicalKey::F1 => "F1",
716            PhysicalKey::F2 => "F2",
717            PhysicalKey::F3 => "F3",
718            PhysicalKey::F4 => "F4",
719            PhysicalKey::F5 => "F5",
720            PhysicalKey::F6 => "F6",
721            PhysicalKey::F7 => "F7",
722            PhysicalKey::F8 => "F8",
723            PhysicalKey::F9 => "F9",
724            PhysicalKey::F10 => "F10",
725            PhysicalKey::F11 => "F11",
726            PhysicalKey::F12 => "F12",
727            PhysicalKey::F13 => "F13",
728            PhysicalKey::F14 => "F14",
729            PhysicalKey::F15 => "F15",
730            PhysicalKey::F16 => "F16",
731            PhysicalKey::F17 => "F17",
732            PhysicalKey::F18 => "F18",
733            PhysicalKey::F19 => "F19",
734            PhysicalKey::F20 => "F20",
735            PhysicalKey::F21 => "F21",
736            PhysicalKey::F22 => "F22",
737            PhysicalKey::F23 => "F23",
738            PhysicalKey::F24 => "F24",
739            PhysicalKey::PrintScreen => "PrintScreen",
740            PhysicalKey::ScrollLock => "ScrollLock",
741            PhysicalKey::Pause => "Pause",
742            PhysicalKey::BrowserBack => "BrowserBack",
743            PhysicalKey::BrowserFavorites => "BrowserFavorites",
744            PhysicalKey::BrowserForward => "BrowserForward",
745            PhysicalKey::BrowserHome => "BrowserHome",
746            PhysicalKey::BrowserRefresh => "BrowserRefresh",
747            PhysicalKey::BrowserSearch => "BrowserSearch",
748            PhysicalKey::BrowserStop => "BrowserStop",
749            PhysicalKey::Eject => "Eject",
750            PhysicalKey::LaunchApp1 => "LaunchApp1",
751            PhysicalKey::LaunchApp2 => "LaunchApp2",
752            PhysicalKey::LaunchMail => "LaunchMail",
753            PhysicalKey::MediaPlayPause => "MediaPlayPause",
754            PhysicalKey::MediaSelect => "MediaSelect",
755            PhysicalKey::MediaStop => "MediaStop",
756            PhysicalKey::MediaTrackNext => "MediaTrackNext",
757            PhysicalKey::MediaTrackPrevious => "MediaTrackPrevious",
758            PhysicalKey::Power => "Power",
759            PhysicalKey::Sleep => "Sleep",
760            PhysicalKey::AudioVolumeDown => "AudioVolumeDown",
761            PhysicalKey::AudioVolumeMute => "AudioVolumeMute",
762            PhysicalKey::AudioVolumeUp => "AudioVolumeUp",
763            PhysicalKey::WakeUp => "WakeUp",
764            PhysicalKey::Again => "Again",
765            PhysicalKey::Copy => "Copy",
766            PhysicalKey::Cut => "Cut",
767            PhysicalKey::Find => "Find",
768            PhysicalKey::Open => "Open",
769            PhysicalKey::Paste => "Paste",
770            PhysicalKey::Props => "Props",
771            PhysicalKey::Select => "Select",
772            PhysicalKey::Undo => "Undo",
773        }
774    }
775
776    /// Parses a member name (ignoring case, aliases included) or the
777    /// numeric value of a defined member.
778    pub fn parse(s: &str) -> Result<PhysicalKey, ParsePhysicalKeyError> {
779        let s = s.trim();
780        if let Some((_, value)) = NAMES.iter().find(|(name, _)| name.eq_ignore_ascii_case(s)) {
781            return Ok(*value);
782        }
783        if let Ok(number) = s.parse::<i32>() {
784            if let Some(value) = Self::from_value(number) {
785                return Ok(value);
786            }
787        }
788        Err(ParsePhysicalKeyError(s.to_string()))
789    }
790}
791
792impl FromStr for PhysicalKey {
793    type Err = ParsePhysicalKeyError;
794
795    fn from_str(s: &str) -> Result<Self, Self::Err> {
796        Self::parse(s)
797    }
798}
799
800impl fmt::Display for PhysicalKey {
801    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
802        f.write_str(self.name())
803    }
804}