INNER CODE UNIT · Rust

parse_key_combo

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

pub fn parse_key_combo(spec: &str) -> Result<(u64, String)> {
    if !spec.contains('+') || spec.chars().count() == 1 {
        return Ok((0, spec.to_string()));
    }
    let (mods, key) = spec.rsplit_once('+').unwrap();
    // "ctrl++" means the key is the plus sign itself.
    let (mods, key) = if key.is_empty() {
        (mods.trim_end_matches('+'), "+")
    } else {
        (mods, key)
    };
    let mut bits = 0u64;
    for m in mods.split('+').filter(|s| !s.is_empty()) {
        bits |= match m.to_ascii_lowercase().as_str() {
            "alt" | "option" | "opt" => MOD_ALT,
            "ctrl" | "control" => MOD_CTRL,
            "meta" | "cmd" | "command" | "super" | "win" => MOD_META,
            "shift" => MOD_SHIFT,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…