kinput

Crates.iokinput
lib.rskinput
version0.3.1
created_at2026-01-10 19:46:26.713887+00
updated_at2026-01-21 03:12:34.385089+00
descriptionLow-level Rust library for input injection and global key capture on Linux
homepage
repositoryhttps://github.com/alan-venv/kinput
max_upload_size
id2034612
size60,367
Alan Silva (alan-venv)

documentation

README

โŒจ๏ธ Kinput

Low-level Rust library for input injection and global key capture on Linux.

Creates virtual devices and captures global input events directly via the kernel subsystem, operating independently of any graphical environment or display server.

โœจ Features

  • ๐Ÿง Kernel-Level: Native virtual device management.
  • โŒจ๏ธ Full Input Support: Keyboard and mouse (relative/absolute) events injection.
  • ๐ŸŽง Global Capture: Reads events from physical devices regardless of window focus.
  • ๐Ÿšซ Headless: No dependencies on X11, Wayland, or compositors.
  • โšก Minimal API: Simple, idiomatic Rust interface.

๐Ÿš€ Usage

Injection

use kinput::{InputDevice, Key::*};

fn main() {
    let device = InputDevice::new();

    device.keyboard.text([H, E, L, L, O, Space, W, O, R, L, D]);

    // Relative movement.
    device.mouse.rel.reset_axis();
    device.mouse.rel.move_xy(500, 350);
    device.mouse.rel.left_click();

    // Absolute positioning.
    device.mouse.abs.move_xy(300, 300);
    device.mouse.abs.left_click();
}

Capture

use kinput::{InputReader, Key::*};

fn main() {
    let mut reader = InputReader::new();
    reader.start().unwrap();

    while let Ok(key) = reader.receive() {
        if key == A {
            println!("A key pressed");
        }
    }
}

๐Ÿ”ง Non-Root Setup

Run this script to configure permissions and use the library without sudo.

#!/bin/bash

MODULE_GROUP=$(stat -c %G /dev/uinput 2>/dev/null || echo "root")
if [ "$MODULE_GROUP" = "input" ]; then
    sudo usermod -aG input "$USER"
else
    RULE_FILE="/etc/udev/rules.d/99-uinput.rules"
    RULE_CONTENT="KERNEL==\"uinput\", MODE=\"0660\", GROUP=\"input\""

    echo "$RULE_CONTENT" | sudo tee "$RULE_FILE" > /dev/null
    sudo udevadm control --reload-rules
    sudo udevadm trigger
    sudo usermod -aG input "$USER"
fi

Note: A system logout/login is required for changes to take effect.

๐ŸŽฏ Scope

  • ๐Ÿค– Bots & Automation
  • ๐Ÿงช Automated Testing
  • โ™ฟ Accessibility Tooling
  • ๐ŸŽฎ Device Emulation
Commit count: 37

cargo fmt