Crates.io | simulate |
lib.rs | simulate |
version | 0.3.0 |
source | src |
created_at | 2020-08-25 21:42:36.182135 |
updated_at | 2020-12-07 00:40:42.787179 |
description | This crate allows you to simulate keystrokes. |
homepage | |
repository | https://github.com/gymore-z/simulate |
max_upload_size | |
id | 280743 |
size | 32,464 |
simulate
allows you to simulate input events (such as keyboard keystrokes or mouse mouvement) through code.
At the movement, only Windows is supported.
simulate
can be used to simulate keyboard keystrokes:
use simulate;
use simulate::Key;
// Release a key
simulate::press(Key::Shift).unwrap();
// Send a key (press + release)
simulate::send(Key::H).unwrap();
// Release a key
simulate::release(Key::Shift).unwrap();
// Send a single character
simulate::send('♪').unwrap();
// Type a string
simulate::type_str("Hello, world!").unwrap();
It can also simulate mouse events:
use simulate::{self, Key};
// Mouse buttons are treated as keys
simulate::send(Key::MouseLeft).unwrap();
// Move the mouse 100 pixels left, 50 pixels down
simulate::move_mouse_relative(100, 50).unwrap();
// Move the mouse at the center of the screen.
simulate::move_mouse_absolute(0.5, 0.5).unwrap();
// Rotate the mouse wheel forward
simulate::scroll(1.0).unwrap();
// Rotate the mouse wheel to the left
simulate::scroll_horizontal(-1.0).unwrap();
Events can be buffered using the EventBuffer
structure:
use simulate::{self, Key, EventBuffer};
// This is really just a Vec<simulate::Event>
let mut buffer = EventBuffer::new();
buffer.press(Key::Shift);
buffer.send(Key::A);
buffer.send(Key::B);
buffer.release(Key::Shift);
buffer.move_mouse_relative(10, 0);
buffer.send(Key::MouseLeft);
buffer.simulate().unwrap();
Events can be created directly with the Event
structure:
use simulate::{self, Event};
let my_event = Event::MoveMouseAbsolute {
x: 0.5,
y: 0.25,
map_to_virtual_desktop: true,
};
// Send a single event
simulate::send_event(my_event).unwrap();