4 releases (2 breaking)
0.3.0 | Dec 7, 2020 |
---|---|
0.2.1 | Sep 15, 2020 |
0.2.0 | Aug 26, 2020 |
0.1.3 | Aug 25, 2020 |
#132 in Simulation
33KB
792 lines
simulate
allows you to simulate input events (such as keyboard keystrokes or mouse mouvement) through code.
Progress
At the movement, only Windows is supported.
Examples
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();
Dependencies
~185KB