Struct rustautogui::RustAutoGui

source ·
pub struct RustAutoGui { /* private fields */ }
Expand description

Main struct for Rustautogui Struct gets assigned keyboard, mouse and struct to it implemented functions execute commands from each of assigned substructs executes also correlation algorithms when doing find_image_on_screen

Implementations§

source§

impl RustAutoGui

source

pub fn new(debug: bool) -> Self

initiation of screen, keyboard and mouse that are assigned to new rustautogui struct. all the other struct fields are initiated as 0 or None

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 6)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn load_and_prepare_template( &mut self, template_path: &str, region: Option<(u32, u32, u32, u32)>, match_mode: MatchMode, max_segments: &Option<u32>, )

Loads template image from provided path and sets all the fields across structs as needed. Depending on match_mode, different template preparation process is executed. When using FFT, region is also important for zero-pad calculation Loading and preparing template is a necessary process before calling find_image_on_screen function

creates vector of data stored under PreparedData enumerator, and stored inside struct field self.prepared_data

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 9)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn change_prepared_settings( &mut self, region: Option<(u32, u32, u32, u32)>, match_mode: MatchMode, max_segments: &Option<u32>, )

change certain settings for prepared template, like region, match_mode or max_segments. If MatchMode is not changed, whole template recalculation may still be needed if certain other parameters are changed, depending on current MatchMode. For FFT, changing region starts complete recalculation again, because of change in zero pad image. While changing max_segments calls recalculation of template for Segmented matchmode

source

pub fn change_debug_state(&mut self, state: bool)

changes debug mode

source

pub fn find_image_on_screen( &mut self, precision: f32, ) -> Option<Vec<(u32, u32, f64)>>

Searches for prepared template on screen. On windows only main monitor search is supported, while on linux, all monitors work more details in README

source

pub fn save_screenshot(&mut self, path: &str)

saves screenshot and saves it at provided path

source

pub fn find_image_on_screen_and_move_mouse( &mut self, precision: f32, moving_time: f32, ) -> Option<Vec<(u32, u32, f64)>>

executes find_image_on_screen and moves mouse to the middle of the image.

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 12)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn move_mouse_to_pos(&self, x: i32, y: i32, moving_time: f32)

moves mouse to x, y pixel coordinate

source

pub fn left_click(&self)

executes left mouse click

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 15)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn right_click(&self)

executes right mouse click

source

pub fn middle_click(&self)

executes middle mouse click

source

pub fn double_click(&self)

executes double left mouse click

source

pub fn scroll_up(&self)

source

pub fn scroll_down(&self)

source

pub fn keyboard_input(&self, input: &str, shifted: &bool)

accepts string and mimics keyboard key presses for each character in string

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 18)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn keyboard_command(&self, input: &str)

executes keyboard command like “return” or “escape”

Examples found in repository?
examples/find_image_move_mouse_and_input.rs (line 21)
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
fn main() {

    // initialize autogui
    let mut gui = rustautogui::RustAutoGui::new(false);

    // load the image searching for. Region is Option<(startx, starty, width, height)> of search. Matchmode FFT or Segmented (not implemented before 1.0 version), max segments, only important for Segmented match mode
    gui.load_and_prepare_template("test.png", Some((0,0, 500, 300)), rustautogui::MatchMode::FFT, &None);

    // automatically move mouse to found template position in this case it was browser url input field
    gui.find_image_on_screen_and_move_mouse(0.9, 1.0);

    // click the url input field
    gui.left_click();

    // input url
    gui.keyboard_input("test.hr", &false);

    // press enter
    gui.keyboard_command("return");


    // maybe you would want to loop search until image is found and break the loop then
    loop {
        let pos = gui.find_image_on_screen_and_move_mouse(0.9, 1.0);    
        match pos {
            Some(_) => break,
            None => (),
        }
    }
}
source

pub fn keyboard_multi_key( &self, input1: &str, input2: &str, input3: Option<&str>, )

Trait Implementations§

source§

impl Drop for RustAutoGui

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more