#![warn(unused_import_braces)]
#![warn(missing_docs)]
#![deny(trivial_casts, trivial_numeric_casts)]
#![deny(unreachable_patterns)]
#![feature(crate_in_paths)]
#![feature(slice_patterns)]
extern crate libc;
extern crate image;
#[cfg(target_os = "macos")] extern crate core_foundation;
#[cfg(target_os = "macos")] extern crate core_graphics;
mod action;
mod actor;
mod keymap;
mod mouse;
mod keyboard;
mod platform;
pub use keymap::Key;
pub use action::MouseButton;
pub use mouse::Mouse;
pub use keyboard::Keyboard;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Position {
pub x: u32,
pub y: u32
}
impl Position {
pub fn new(x: u32, y: u32) -> Position {
Position { x, y }
}
pub fn distance_to(&self, other: Position) -> u32 {
let dx = (self.x.max(other.x) - self.x.max(other.x)).pow(2);
let dy = (self.y.max(other.y) - self.y.max(other.y)).pow(2);
((dx + dy) as f32).sqrt().round() as u32
}
}
pub struct AutoGUI {
pub mouse: mouse::Mouse,
pub keyboard: keyboard::Keyboard,
}
impl AutoGUI {
pub fn new() -> AutoGUI {
AutoGUI {
mouse: mouse::Mouse::new(),
keyboard: keyboard::Keyboard::new(),
}
}
pub fn screenshot() -> Vec<image::RgbaImage> {
#[cfg(target_os = "macos")]
platform::macos::screenshot::all_screens()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mouse_move() {
AutoGUI::new().mouse.move_to(Position::new(100, 100));
}
}