inputkit 0.1.0

Keyboard and mouse input automation for Windows
Documentation
use std::{thread, time::Duration};

use inputkit::{Key, MouseButton, keyboard, mouse};

fn main() {
    // The first call installs the global wheel listener. Later calls consume
    // the movement accumulated since the preceding call.
    if mouse::scroll_delta().is_none() {
        eprintln!("Could not start global mouse-wheel detection");
        return;
    }

    println!("Click or scroll the mouse. Press Escape to quit.");

    loop {
        if mouse::pressed(MouseButton::Left) {
            let (x, y) = mouse::position();
            println!("Left click at {x}, {y}");
        }
        if mouse::pressed(MouseButton::Right) {
            println!("Right click");
        }
        if let Some(delta) = mouse::scroll_delta() {
            if delta.is_up() {
                println!("Scrolled up by {} units", delta.vertical);
            } else if delta.is_down() {
                println!("Scrolled down by {} units", -delta.vertical);
            }

            if delta.horizontal != 0 {
                println!("Horizontal wheel delta: {}", delta.horizontal);
            }
        }
        if keyboard::pressed(Key::Escape) {
            break;
        }

        thread::sleep(Duration::from_millis(10));
    }
}