#mouse #mouse-event #keyboard #macro #virtual-keyboard #virtual-mouse

umacro-lib

Simulate Keyboard & Mouse events in Linux (X11 & Wayland) with uinput

1 unstable release

0.1.0 Nov 27, 2024

#962 in Hardware support

Download history 128/week @ 2024-11-25 19/week @ 2024-12-02 7/week @ 2024-12-09

154 downloads per month

MIT license

11KB
221 lines

umacro-lib

Simulate Keyboard & Mouse events in Linux (X11 & Wayland) with uinput.

Example:

Mouse

// Create a virtual device:
let mut device = create_virtual_device()?;

// Wait for device initialization:
device.wait(200);

// Absolute mouse movement
device.mouse_move(250, 200)?;
device.wait(500);

// Mouse Down
device.mouse_down(Mouse::Left)?;
device.wait(1000);

// Relative Mouse Movement
device.mouse_move_relative(150, 150)?;
device.wait(500);

// Mouse Up
device.mouse_up(Mouse::Left)?;
device.wait(500);

// Mouse Up & Down (Click)
device.mouse_click(Mouse::Right)?;

Keyboard

let mut device = create_virtual_device()?;

device.wait(3000); // Wait 3 seconds to initialize keyboard

// This is case insensitive, it presses real keyboard buttons, not sending chars.
// So you can't write emojis and special characters here.
// 10 is wait milliseconds between key presses
device.key_write("hello world", 10)?;

// Key Press & Release (Click)
device.key(Key::Space)?;

//If you want to write BIG chars, press down shift before, then release.
device.key_down(Key::LeftShift)?;
device.key_write("big hello world", 200)?; // result: "BIG HELLO WORLD"
device.key_up(Key::LeftShift)?;

Dependencies

~2MB
~46K SLoC