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:
```rust
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: ```rust 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::movemouserelative(100, 50).unwrap();
// Move the mouse at the center of the screen. simulate::movemouseabsolute(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:
```rust
use simulate::{self, Key, EventBuffer};
// This is really just a Vec
buffer.press(Key::Shift); buffer.send(Key::A); buffer.send(Key::B); buffer.release(Key::Shift);
buffer.movemouserelative(10, 0); buffer.send(Key::MouseLeft);
buffer.simulate().unwrap(); ```
Events can be created directly with the Event
structure:
```rust
use simulate::{self, Event};
let myevent = Event::MoveMouseAbsolute { x: 0.5, y: 0.25, maptovirtualdesktop: true, };
// Send a single event simulate::sendevent(myevent).unwrap(); ```