MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / parse_hid_key

Function parse_hid_key

packages/server/src/main/input_helpers.rs:178–206  ·  view source on GitHub ↗
(value: &str)

Source from the content-addressed store, hash-verified

176}
177
178fn parse_hid_key(value: &str) -> Result<u16, crate::error::AppError> {
179 if let Ok(code) = value.parse::<u16>() {
180 return Ok(code);
181 }
182 let key = match value.to_lowercase().as_str() {
183 "enter" | "return" => HID_KEY_ENTER,
184 "escape" | "esc" => 41,
185 "backspace" | "delete" => 42,
186 "tab" => 43,
187 "space" => 44,
188 "right" | "arrow-right" => HID_KEY_ARROW_RIGHT,
189 "left" | "arrow-left" => HID_KEY_ARROW_LEFT,
190 "down" | "arrow-down" => HID_KEY_ARROW_DOWN,
191 "up" | "arrow-up" => HID_KEY_ARROW_UP,
192 "home" => 74,
193 "end" => 77,
194 other if other.len() == 1 => hid_for_character(other.chars().next().unwrap())
195 .map(|(key, _)| key)
196 .ok_or_else(|| {
197 crate::error::AppError::bad_request(format!("Unsupported key `{value}`."))
198 })?,
199 _ => {
200 return Err(crate::error::AppError::bad_request(format!(
201 "Unsupported key `{value}`."
202 )))
203 }
204 };
205 Ok(key)
206}
207
208fn parse_modifier_mask(value: &str) -> Result<u32, crate::error::AppError> {
209 let mut mask = 0;

Callers 4

mainFunction · 0.85
run_batch_stepFunction · 0.85
run_maestro_commandFunction · 0.85
parse_key_listFunction · 0.85

Calls 2

hid_for_characterFunction · 0.50
as_strMethod · 0.45

Tested by

no test coverage detected