1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![allow(dead_code)]

#![feature(crate_in_paths)]

extern crate libc;

#[cfg(target_os = "macos")]
extern crate core_graphics;

mod action;
mod mouse;
mod keymap;
mod keyboard;
mod platform;

#[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 }
    }
    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
    }
}


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(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::time::Duration;
    use std::thread::sleep;

    #[test]
    fn test_name() {
        let gui = AutoGUI::new();

        let mut m = gui.mouse;
        let mut k = gui.keyboard;

        m = m.at(Position::new(1370, 70)).drag_to(action::MouseButton::Left, Position::new(1370, 200));
        m.at(Position::new(80, 80)).doubleclick();


        use keymap::Key;

        k = k.press(Key::LeftSuper).tap(Key::T).release(Key::LeftSuper);
        k = k.tap(Key::L);
        k = k.tap(Key::S);
        k = k.tap(Key::Space);
        k = k.tap(Key::Minus);
        k = k.tap(Key::L);
        k = k.tap(Key::Return);
        sleep(Duration::from_millis(5000));
        k.press(Key::LeftCtrl).tap(Key::D).release(Key::LeftCtrl);
    }
}