A simple Rust library for simulating keyboard input using the enigo
crate. This library provides an easy-to-use interface for sending key combinations programmatically.
cargo add simulate_key
- Simple API: Simulate key combinations with string-based input
- Comprehensive Key Support: Function keys (F1-F24), navigation, numpad, media keys, and more
- Modifier Support: Ctrl, Shift, Alt, Meta/Win/Cmd combinations
- Key Hold: Hold keys for specified durations
- Cross-platform: Works on Windows, macOS, and Linux via
enigo
Add this to your Cargo.toml
:
[dependencies]
simulate_key = "0.1.1"
use simulate_key::simulate_key;
fn main() {
// Basic key combinations
simulate_key("ctrl+c").unwrap();
simulate_key("alt+tab").unwrap();
simulate_key("ctrl+shift+t").unwrap();
// Function keys
simulate_key("f5").unwrap();
simulate_key("ctrl+f12").unwrap();
// Navigation
simulate_key("ctrl+home").unwrap();
simulate_key("shift+end").unwrap();
// Single characters
simulate_key("a").unwrap();
simulate_key("enter").unwrap();
// Hold keys
use simulate_key::simulate_key_hold;
simulate_key_hold("space", 500).unwrap(); // Hold space for 500ms
}
ctrl
,control
shift
alt
meta
,win
,cmd
,command
f1
throughf24
home
,end
pageup
,pgup
,pagedown
,pgdn
left
,right
,up
,down
insert
,ins
,delete
,del
enter
,return
tab
,space
,backspace
escape
,esc
capslock
,numlock
,scrolllock
printscreen
,prtsc
,pause
numpad0
throughnumpad9
numpadenter
,numpadplus
,numpadminus
numpadmultiply
,numpaddivide
,numpaddot
volumeup
,volumedown
,volumemute
mediaplay
,mediastop
,medianext
,mediaprev
Any single character (letters, numbers, symbols)
The library returns ParseKeyError
for invalid key combinations:
match simulate_key("invalid+key") {
Ok(()) => println!("Key simulated successfully"),
Err(e) => println!("Error: {}", e),
}