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
impl RustAutoGui
sourcepub fn new(debug: bool) -> Self
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?
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 => (),
}
}
}sourcepub fn load_and_prepare_template(
&mut self,
template_path: &str,
region: Option<(u32, u32, u32, u32)>,
match_mode: MatchMode,
max_segments: &Option<u32>,
)
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?
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 => (),
}
}
}sourcepub fn change_prepared_settings(
&mut self,
region: Option<(u32, u32, u32, u32)>,
match_mode: MatchMode,
max_segments: &Option<u32>,
)
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
sourcepub fn change_debug_state(&mut self, state: bool)
pub fn change_debug_state(&mut self, state: bool)
changes debug mode
sourcepub fn find_image_on_screen(
&mut self,
precision: f32,
) -> Option<Vec<(u32, u32, f64)>>
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
sourcepub fn save_screenshot(&mut self, path: &str)
pub fn save_screenshot(&mut self, path: &str)
saves screenshot and saves it at provided path
sourcepub fn find_image_on_screen_and_move_mouse(
&mut self,
precision: f32,
moving_time: f32,
) -> Option<Vec<(u32, u32, f64)>>
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?
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 => (),
}
}
}sourcepub fn move_mouse_to_pos(&self, x: i32, y: i32, moving_time: f32)
pub fn move_mouse_to_pos(&self, x: i32, y: i32, moving_time: f32)
moves mouse to x, y pixel coordinate
sourcepub fn left_click(&self)
pub fn left_click(&self)
executes left mouse click
Examples found in repository?
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 => (),
}
}
}sourcepub fn right_click(&self)
pub fn right_click(&self)
executes right mouse click
sourcepub fn middle_click(&self)
pub fn middle_click(&self)
executes middle mouse click
sourcepub fn double_click(&self)
pub fn double_click(&self)
executes double left mouse click
pub fn scroll_up(&self)
pub fn scroll_down(&self)
sourcepub fn keyboard_input(&self, input: &str, shifted: &bool)
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?
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 => (),
}
}
}sourcepub fn keyboard_command(&self, input: &str)
pub fn keyboard_command(&self, input: &str)
executes keyboard command like “return” or “escape”
Examples found in repository?
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 => (),
}
}
}pub fn keyboard_multi_key( &self, input1: &str, input2: &str, input3: Option<&str>, )
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RustAutoGui
impl RefUnwindSafe for RustAutoGui
impl !Send for RustAutoGui
impl !Sync for RustAutoGui
impl Unpin for RustAutoGui
impl UnwindSafe for RustAutoGui
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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