Skip to content

Instantly share code, notes, and snippets.

@Japanuspus
Created October 14, 2021 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Japanuspus/d3ef776fa451382ece8a24315b38afd5 to your computer and use it in GitHub Desktop.
Save Japanuspus/d3ef776fa451382ece8a24315b38afd5 to your computer and use it in GitHub Desktop.
Cross-platform global hotkey in Rust
use tauri_hotkey as hotkey; // Discontinued, but v0.1.2 is working fine as of 2021-10-14
use std::io::{stdin, Read};
fn main() {
let spec = "ctrl+alt+r";
let mut hk = hotkey::HotkeyManager::new();
let key = hotkey::parse_hotkey(&spec).unwrap();
println!("Listening for {}. Enter to exit", &spec);
hk.register(key, move || println!("{} pressed!", &spec)).unwrap();
stdin().read(&mut [0]).unwrap(); // wait for "enter"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment