1use postcard::experimental::max_size::MaxSize;
4use serde::{Deserialize, Serialize};
5
6use super::hid::HidKeyCode;
7
8#[non_exhaustive]
11#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord, MaxSize)]
12#[cfg_attr(feature = "_codegen", derive(strum::EnumIter))]
13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
14#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
15#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
16pub enum ConsumerKey {
17 No,
18 SnapShot,
20 BrightnessUp,
22 BrightnessDown,
23 Play,
25 Pause,
26 Record,
27 FastForward,
28 Rewind,
29 NextTrack,
30 PrevTrack,
31 StopPlay,
32 Eject,
33 RandomPlay,
34 Repeat,
35 StopEject,
36 PlayPause,
37 Mute,
39 VolumeIncrement,
40 VolumeDecrement,
41 Reserved,
42 Email,
44 Calculator,
45 LocalBrowser,
46 Lock,
47 ControlPanel,
48 Assistant,
49 New,
51 Open,
52 Close,
53 Exit,
54 Maximize,
55 Minimize,
56 Save,
57 Print,
58 Properties,
59 Undo,
60 Copy,
61 Cut,
62 Paste,
63 SelectAll,
64 Find,
65 Search,
66 Home,
67 Back,
68 Forward,
69 Stop,
70 Refresh,
71 Bookmarks,
72 NextKeyboardLayoutSelect,
73 DesktopShowAllWindows,
74 AcSoftKeyLeft,
75}
76
77impl From<u16> for ConsumerKey {
78 fn from(value: u16) -> Self {
79 match value {
80 0x00 => Self::No,
81 0x65 => Self::SnapShot,
82 0x6F => Self::BrightnessUp,
83 0x70 => Self::BrightnessDown,
84 0xB0 => Self::Play,
85 0xB1 => Self::Pause,
86 0xB2 => Self::Record,
87 0xB3 => Self::FastForward,
88 0xB4 => Self::Rewind,
89 0xB5 => Self::NextTrack,
90 0xB6 => Self::PrevTrack,
91 0xB7 => Self::StopPlay,
92 0xB8 => Self::Eject,
93 0xB9 => Self::RandomPlay,
94 0xBC => Self::Repeat,
95 0xCC => Self::StopEject,
96 0xCD => Self::PlayPause,
97 0xE2 => Self::Mute,
98 0xE9 => Self::VolumeIncrement,
99 0xEA => Self::VolumeDecrement,
100 0xEB => Self::Reserved,
101 0x18A => Self::Email,
102 0x192 => Self::Calculator,
103 0x194 => Self::LocalBrowser,
104 0x19E => Self::Lock,
105 0x19F => Self::ControlPanel,
106 0x1CB => Self::Assistant,
107 0x201 => Self::New,
108 0x202 => Self::Open,
109 0x203 => Self::Close,
110 0x204 => Self::Exit,
111 0x205 => Self::Maximize,
112 0x206 => Self::Minimize,
113 0x207 => Self::Save,
114 0x208 => Self::Print,
115 0x209 => Self::Properties,
116 0x21A => Self::Undo,
117 0x21B => Self::Copy,
118 0x21C => Self::Cut,
119 0x21D => Self::Paste,
120 0x21E => Self::SelectAll,
121 0x21F => Self::Find,
122 0x221 => Self::Search,
123 0x223 => Self::Home,
124 0x224 => Self::Back,
125 0x225 => Self::Forward,
126 0x226 => Self::Stop,
127 0x227 => Self::Refresh,
128 0x22A => Self::Bookmarks,
129 0x29D => Self::NextKeyboardLayoutSelect,
130 0x29F => Self::DesktopShowAllWindows,
131 0x2A0 => Self::AcSoftKeyLeft,
132 _ => Self::No,
133 }
134 }
135}
136
137impl From<ConsumerKey> for u16 {
138 fn from(value: ConsumerKey) -> Self {
139 match value {
140 ConsumerKey::No => 0x00,
141 ConsumerKey::SnapShot => 0x65,
142 ConsumerKey::BrightnessUp => 0x6F,
143 ConsumerKey::BrightnessDown => 0x70,
144 ConsumerKey::Play => 0xB0,
145 ConsumerKey::Pause => 0xB1,
146 ConsumerKey::Record => 0xB2,
147 ConsumerKey::FastForward => 0xB3,
148 ConsumerKey::Rewind => 0xB4,
149 ConsumerKey::NextTrack => 0xB5,
150 ConsumerKey::PrevTrack => 0xB6,
151 ConsumerKey::StopPlay => 0xB7,
152 ConsumerKey::Eject => 0xB8,
153 ConsumerKey::RandomPlay => 0xB9,
154 ConsumerKey::Repeat => 0xBC,
155 ConsumerKey::StopEject => 0xCC,
156 ConsumerKey::PlayPause => 0xCD,
157 ConsumerKey::Mute => 0xE2,
158 ConsumerKey::VolumeIncrement => 0xE9,
159 ConsumerKey::VolumeDecrement => 0xEA,
160 ConsumerKey::Reserved => 0xEB,
161 ConsumerKey::Email => 0x18A,
162 ConsumerKey::Calculator => 0x192,
163 ConsumerKey::LocalBrowser => 0x194,
164 ConsumerKey::Lock => 0x19E,
165 ConsumerKey::ControlPanel => 0x19F,
166 ConsumerKey::Assistant => 0x1CB,
167 ConsumerKey::New => 0x201,
168 ConsumerKey::Open => 0x202,
169 ConsumerKey::Close => 0x203,
170 ConsumerKey::Exit => 0x204,
171 ConsumerKey::Maximize => 0x205,
172 ConsumerKey::Minimize => 0x206,
173 ConsumerKey::Save => 0x207,
174 ConsumerKey::Print => 0x208,
175 ConsumerKey::Properties => 0x209,
176 ConsumerKey::Undo => 0x21A,
177 ConsumerKey::Copy => 0x21B,
178 ConsumerKey::Cut => 0x21C,
179 ConsumerKey::Paste => 0x21D,
180 ConsumerKey::SelectAll => 0x21E,
181 ConsumerKey::Find => 0x21F,
182 ConsumerKey::Search => 0x221,
183 ConsumerKey::Home => 0x223,
184 ConsumerKey::Back => 0x224,
185 ConsumerKey::Forward => 0x225,
186 ConsumerKey::Stop => 0x226,
187 ConsumerKey::Refresh => 0x227,
188 ConsumerKey::Bookmarks => 0x22A,
189 ConsumerKey::NextKeyboardLayoutSelect => 0x29D,
190 ConsumerKey::DesktopShowAllWindows => 0x29F,
191 ConsumerKey::AcSoftKeyLeft => 0x2A0,
192 }
193 }
194}
195
196impl ConsumerKey {
197 #[cfg(feature = "_codegen")]
199 pub fn all() -> impl Iterator<Item = Self> {
200 <Self as strum::IntoEnumIterator>::iter()
201 }
202
203 pub fn to_hid_keycode(&self) -> Option<HidKeyCode> {
205 match self {
206 ConsumerKey::Mute => Some(HidKeyCode::AudioMute),
207 ConsumerKey::VolumeIncrement => Some(HidKeyCode::AudioVolUp),
208 ConsumerKey::VolumeDecrement => Some(HidKeyCode::AudioVolDown),
209 ConsumerKey::NextTrack => Some(HidKeyCode::MediaNextTrack),
210 ConsumerKey::PrevTrack => Some(HidKeyCode::MediaPrevTrack),
211 ConsumerKey::StopPlay => Some(HidKeyCode::MediaStop),
212 ConsumerKey::PlayPause => Some(HidKeyCode::MediaPlayPause),
213 ConsumerKey::Record => Some(HidKeyCode::MediaSelect),
214 ConsumerKey::Eject => Some(HidKeyCode::MediaEject),
215 ConsumerKey::Email => Some(HidKeyCode::Mail),
216 ConsumerKey::Calculator => Some(HidKeyCode::Calculator),
217 ConsumerKey::LocalBrowser => Some(HidKeyCode::MyComputer),
218 ConsumerKey::Search => Some(HidKeyCode::WwwSearch),
219 ConsumerKey::Home => Some(HidKeyCode::WwwHome),
220 ConsumerKey::Back => Some(HidKeyCode::WwwBack),
221 ConsumerKey::Forward => Some(HidKeyCode::WwwForward),
222 ConsumerKey::Stop => Some(HidKeyCode::WwwStop),
223 ConsumerKey::Refresh => Some(HidKeyCode::WwwRefresh),
224 ConsumerKey::Bookmarks => Some(HidKeyCode::WwwFavorites),
225 ConsumerKey::FastForward => Some(HidKeyCode::MediaFastForward),
226 ConsumerKey::Rewind => Some(HidKeyCode::MediaRewind),
227 ConsumerKey::BrightnessUp => Some(HidKeyCode::BrightnessUp),
228 ConsumerKey::BrightnessDown => Some(HidKeyCode::BrightnessDown),
229 ConsumerKey::ControlPanel => Some(HidKeyCode::ControlPanel),
230 ConsumerKey::Assistant => Some(HidKeyCode::Assistant),
231 ConsumerKey::DesktopShowAllWindows => Some(HidKeyCode::MissionControl),
232 ConsumerKey::AcSoftKeyLeft => Some(HidKeyCode::Launchpad),
233 _ => None,
234 }
235 }
236}