Files
rustautogui/examples/find_image_move_mouse_and_input.rs
9e2d31ad6d V2.5.0 - Opencl + more github actions + code refactor + tests + custom threshold + lite + dev
* opencl first buggy implementation

* more work on opencl. Buggy atm

* WORKING ALGORITHM ATM but slow

* working opencl code with implemented 2 step fully

* first reworks. addition of new fields in struct and some cleanup

* more changes. added a struct for memory buffers, creation of it, new functions for gui dedicated opencl template match

* more changes, no errors

* added to main functions in lib. Not tested yet

* first tests done, code working. Needs more optimisation

* some testing prints, code retested after fix in time measurement. Looks promising

* revert back

* tested optimisations reimplemented and working

* a bit more optimisations

* added opencl feature

* fmt

* added change ocl state, graceful exits

* windows fix

* small optimisation

* macos fix

* different variations of tests

* currently a fine solution to auto determine treshold of fast segmentation

* derivative activation only in opencl mode

* readme update

* add v2 algorithm

* added table of contents to readme

* update changelog (no date included yet)

* moved all the additional v2 buffers  under GpuMemoryPointers struct

* additional work on v2

* unifying v1 and v2 kernels + other data

* working on adding devices info

* more work done on detecting devices, creating kernels and moving kernels to precalculated

* working state of code. Implemented different OCL things, Kernel building outside of OCL Kernel storage, most of logic for V2.

* added v2 into logic. remaining to create standalone lib.rs functions

* various fixes

* added precision to buffer passed to GPU and updated

* adding more matchmodes and covering

* cleaning up code

* moving some enums to structs

* changes on lots of stuff, including changing device for OCL

* implemented lite feature

* changes on lite code, removed problems

* renamed template match

* cleaned unnecesary conditions

* fixed issue with memory not cleaned up on v2

* readme update and fix on matchmode

* fix for region on ocl matching

* fixes for ltie mode

* added opencl example

* fix for v2 opencl

* fix on opencl device choice to not take cpu

* lite fixes on macos

* linux fixes

* windows fix

* moved files to CORE folder

* full code restructure

* full code restructure

* started with testing

* more tests

* additional mac tests

* linux additions

* linux fixes + cargo.toml editing

* more fixes

* clippy fixes

* github action update

---------

Co-authored-by: DavorMar <[email protected]>
2025-04-27 14:00:11 +02:00

91 lines
3.2 KiB
Rust

fn main() {
#[cfg(not(feature = "lite"))]
{
use rustautogui;
use rustautogui::imgtools;
// initialize autogui
let mut gui = rustautogui::RustAutoGui::new(false).unwrap();
// displays (x, y) size of screen
// especially useful on linux where screen from all monitors is grabbed
gui.get_screen_size();
{
// 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.prepare_template_from_file(
"test.png",
Some((0, 0, 500, 300)),
rustautogui::MatchMode::FFT,
)
.unwrap();
}
// or another way to prepare template
{
let img = imgtools::load_image_rgba("test.png").unwrap(); // just loading this way for example
gui.prepare_template_from_imagebuffer(
img,
Some((0, 0, 700, 500)),
rustautogui::MatchMode::Segmented,
)
.unwrap();
}
// or segmented variant with no region
gui.prepare_template_from_file("test.png", None, rustautogui::MatchMode::FFT)
.unwrap();
// change prepare template settings, like region, matchmode or max segments
// automatically move mouse to found template position, execute movement for 1 second
gui.find_image_on_screen_and_move_mouse(0.9, 1.0).unwrap();
//move mouse to position (in this case to bottom left of stanard 1920x1080 monitor), move the mouse for 1 second
gui.move_mouse_to_pos(1920, 1080, 1.0).unwrap();
// execute left click, move the mouse to x (500), y (500) position for 1 second, release mouse click
// used for actions like moving icons or files
// suggestion: dont use very small moving time values, especially on mac
gui.drag_mouse(500, 500, 1.0).unwrap();
// execute mouse left click
gui.left_click().unwrap();
// execute mouse right click
gui.right_click().unwrap();
// execute mouse middle click
gui.middle_click().unwrap();
// execute a double (left) mouse click
gui.double_click().unwrap();
// mouse scrolls
gui.scroll_down(1).unwrap();
gui.scroll_up(5).unwrap();
gui.scroll_right(8).unwrap();
gui.scroll_left(10).unwrap();
// input keyboard string
gui.keyboard_input("test.com").unwrap();
// press a keyboard command, in this case enter(return)
gui.keyboard_command("return").unwrap();
// two key press
gui.keyboard_multi_key("alt", "tab", None).unwrap();
// three key press
gui.keyboard_multi_key("shift", "control", Some("e"))
.unwrap();
// 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).unwrap();
match pos {
Some(_) => break,
None => (),
}
}
}
}