2 releases

0.1.1 Aug 4, 2025
0.1.0 Jul 15, 2025

#873 in Hardware support

25 downloads per month

MIT license

24KB
386 lines

Keyboard Chords

keyboard-chords is a Rust library for simulating keyboard input events on Windows, with a focus on sending complex "chords" (combinations of key presses) in a simple and ergonomic way.


Features

  • Send Chords: Simulate pressing multiple keys at once, with customizable durations for each key.
  • Typewriter Effect: Easily add randomized delays between key presses to mimic human typing.
  • Bulk Input: All key events in a chord are sent in a single system call for accuracy and speed.
  • Unicode & Virtual Keys: Supports both Unicode characters and virtual key codes.

Quickstart

use keyboard_chords::Chord;
use std::time::Duration;

#[tokio::main]
async fn main() {
    // Create a new chord
    let mut chord = Chord::new();

    // Pushing a string will append the required key presses
    chord.push_str("Hello, world!");

    // Emulate typing delay of 25 to 175ms per keypress
    chord.typewriter(25..175);

    // Wait some time before playing the keys back
    chord.play_after(Duration::from_millis(500)).await;
}

Usage

Add to your Cargo.toml:

[dependencies]
keyboard-chords = "0.1.0"
tokio = { version = "1", features = ["full"] }

Basic API

  • Chord::new(): Create a new chord.
  • chord.push(press): Add a key press to the chord.
  • chord.push_str("text"): Add key presses for each character in a string.
  • chord.typewriter(range): Add random delays to each key press.
  • chord.play().await: Play the chord immediately.
  • chord.play_after(duration).await: Play the chord after a delay.

See main.rs for some more example usage.


Platform Support

Currently, keyboard-chords supports Windows only, using the SendInput API via the windows crate.


License

This project is licensed under the MIT License. See LICENSE for details.


Contributing

Contributions, issues, and feature requests are welcome! Please open an issue or submit a pull request on GitHub.


Dependencies

~126MB
~2M SLoC