keyboard_types/location.rs
1/// The location attribute contains an indication of the physical location of the key on the device.
2///
3/// Certain keys on the keyboard can have the same value, but are in different locations. For
4/// instance, the <kbd>Shift</kbd> key can be on the left or right side of the keyboard, or the
5/// number keys can be above the letters or on the numpad. This enum allows differentiating them.
6///
7/// See also [MDN's documentation](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location).
8#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub enum Location {
11 /// The key is in its "normal" location on the keyboard.
12 ///
13 /// The key activation MUST NOT be distinguished as the left or right
14 /// version of the key, and (other than the `NumLock` key) did not
15 /// originate from the numeric keypad (or did not originate with a
16 /// virtual key corresponding to the numeric keypad).
17 ///
18 /// This variant is the default, and is also used when the location of the key cannot be
19 /// identified.
20 ///
21 /// # Example
22 ///
23 /// The <kbd>1</kbd> key above the <kbd>Q</kbd> key on a QWERTY keyboard will use this location.
24 ///
25 #[doc = include_str!("../docs/keyboard_standard_1_key.svg")]
26 ///
27 /// <sub>For image attribution, see the [ATTRIBUTION.md] file.</sub>
28 ///
29 #[doc = concat!(
30 "[ATTRIBUTION.md]: https://docs.rs/crate/keyboard-types/",
31 env!("CARGO_PKG_VERSION"),
32 "/source/docs/ATTRIBUTION.md",
33 )]
34 Standard = 0x00,
35
36 /// The key activated originated from the left key location (when there
37 /// is more than one possible location for this key).
38 ///
39 /// # Example
40 ///
41 /// The left <kbd>Shift</kbd> key below the <kbd>Caps Lock</kbd> key on a QWERTY keyboard will
42 /// use this location.
43 ///
44 #[doc = include_str!("../docs/keyboard_left_shift_key.svg")]
45 ///
46 /// <sub>For image attribution, see the [ATTRIBUTION.md] file.</sub>
47 ///
48 #[doc = concat!(
49 "[ATTRIBUTION.md]: https://docs.rs/crate/keyboard-types/",
50 env!("CARGO_PKG_VERSION"),
51 "/source/docs/ATTRIBUTION.md",
52 )]
53 Left = 0x01,
54
55 /// The key activation originated from the right key location (when
56 /// there is more than one possible location for this key).
57 ///
58 /// # Example
59 ///
60 /// The right <kbd>Shift</kbd> key below the <kbd>Enter</kbd> key on a QWERTY keyboard will use
61 /// this location.
62 ///
63 #[doc = include_str!("../docs/keyboard_right_shift_key.svg")]
64 ///
65 /// <sub>For image attribution, see the [ATTRIBUTION.md] file.</sub>
66 ///
67 #[doc = concat!(
68 "[ATTRIBUTION.md]: https://docs.rs/crate/keyboard-types/",
69 env!("CARGO_PKG_VERSION"),
70 "/source/docs/ATTRIBUTION.md",
71 )]
72 Right = 0x02,
73
74 /// The key activation originated on the numeric keypad or with a virtual
75 /// key corresponding to the numeric keypad (when there is more than one
76 /// possible location for this key). Note that the `NumLock` key should
77 /// always be encoded with a location of `Location::Standard`.
78 ///
79 /// # Example
80 ///
81 /// The <kbd>1</kbd> key on the numpad will use this location.
82 ///
83 #[doc = include_str!("../docs/keyboard_numpad_1_key.svg")]
84 ///
85 /// <sub>For image attribution, see the [ATTRIBUTION.md] file.</sub>
86 ///
87 #[doc = concat!(
88 "[ATTRIBUTION.md]: https://docs.rs/crate/keyboard-types/",
89 env!("CARGO_PKG_VERSION"),
90 "/source/docs/ATTRIBUTION.md",
91 )]
92 Numpad = 0x03,
93}