INNER CODE UNIT · Rust

press

keon/browser-control · src/actions.rs:179

pub async fn press(c: &mut Cdp, spec: &str) -> Result<()> {
    let (modifiers, key) = parse_key_combo(spec)?;
    let (vk, code, text) = key_info(&key).with_context(|| format!("unknown key {key:?}"))?;
    // With Ctrl/Cmd/Alt held this is a shortcut, not typing: rawKeyDown with no
    // text, otherwise Chrome treats e.g. ctrl+a as a printable "a". Plain keys
    // carry text on keyDown only — a separate char event double-inserts.
    let shortcut = modifiers & (MOD_ALT | MOD_CTRL | MOD_META) != 0;
    let base = json!({"key":key,"code":code,"modifiers":modifiers,"windowsVirtualKeyCode":vk,"nativeVirtualKeyCode":vk});
    let mut down = base.clone();
    down["type"] = json!(if shortcut { "rawKeyDown" } else { "keyDown" });
    if shortcut {
        if let Some(cmd) = editing_command(modifiers, &key) {
            down["commands"] = json!([cmd]);
        }
    } else if let Some(t) = &text {
        down["text"] = json!(t);
    }
    c.call("Input.dispatchKeyEvent", down, true).await?;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…