simulate_key 0.1.0

A simple key combination simulator using enigo
Documentation
  • Coverage
  • 60%
    3 out of 5 items documented2 out of 4 items with examples
  • Size
  • Source code size: 33.94 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.85 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 31s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vtempest

Simulate Key

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.

Features

  • 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

Installation

Add this to your Cargo.toml:

[dependencies]
key-simulator = "0.1.0"

Usage

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
}

Supported Keys

Modifiers

  • ctrl, control
  • shift
  • alt
  • meta, win, cmd, command

Function Keys

  • f1 through f24

Navigation

  • home, end
  • pageup, pgup, pagedown, pgdn
  • left, right, up, down
  • insert, ins, delete, del

Special Keys

  • enter, return
  • tab, space, backspace
  • escape, esc
  • capslock, numlock, scrolllock
  • printscreen, prtsc, pause

Numpad

  • numpad0 through numpad9
  • numpadenter, numpadplus, numpadminus
  • numpadmultiply, numpaddivide, numpaddot

Media Keys

  • volumeup, volumedown, volumemute
  • mediaplay, mediastop, medianext, mediaprev

Single Characters

Any single character (letters, numbers, symbols)

Error Handling

The library returns ParseKeyError for invalid key combinations:

match simulate_key("invalid+key") {
    Ok(()) => println!("Key simulated successfully"),
    Err(e) => println!("Error: {}", e),
}