Skip to main content

cdp_driver/
keys.rs

1//! Keyboard names as `Input.dispatchKeyEvent` wants them.
2
3/// The `code` and Windows virtual key code for a key name.
4///
5/// Unrecognised keys pass through with a virtual key code of 0, which is what
6/// CDP expects for printable characters that carry no special code.
7pub fn key_info(key: &str) -> (&str, u32) {
8    match key {
9        "Enter" => ("Enter", 13),
10        "Tab" => ("Tab", 9),
11        "Backspace" => ("Backspace", 8),
12        "Delete" => ("Delete", 46),
13        "Escape" => ("Escape", 27),
14        " " | "Space" => ("Space", 32),
15        "ArrowLeft" => ("ArrowLeft", 37),
16        "ArrowUp" => ("ArrowUp", 38),
17        "ArrowRight" => ("ArrowRight", 39),
18        "ArrowDown" => ("ArrowDown", 40),
19        _ => (key, 0),
20    }
21}