11 个版本
0.2.2 | 2023年4月14日 |
---|---|
0.2.1 | 2023年4月13日 |
0.1.7 | 2023年3月30日 |
0.1.5 | 2022年8月23日 |
#670 in 开发工具
每月 29 次下载
14KB
177 代码行
rsautogui
rsautogui
旨在成为一个跨平台 GUI 自动化 Rust crate。- 它允许您控制鼠标和键盘以自动化与其他应用程序的交互。
- 目前,它是多个 Rust crate 的包装器,以 Rust 编写类似 pyautogui 的语法。
警告 未在 Linux 和 MacOS 上测试
安装
在您的项目目录中运行以下 Cargo 命令
cargo add rsautogui
示例用法
鼠标
use rsautogui::{mouse, mouse::Speed, mouse::Button, mouse::ScrollAxis};
fn main() {
let pos: (u16, u16) = mouse::position(); // Returns the current mouse coordinates.
mouse::move_to(500, 500); // Moves mouse to x, y instantly.
mouse::slow_move_to(500, 500, Speed::Faster); // Moves mouse to x, y with the specified speed.
mouse::move_rel(500, 500); // Moves mouse to x, y relative to current position instantly.
mouse::slow_move_rel(500, 500, Speed::Fast); // Moves mouse to x, y relative to current position with the specified speed.
mouse::drag_to(500, 500); // Drags mouse to x, y instantly.
mouse::slow_drag_to(500, 500, Speed::Slow); // Drags mouse to x, y with the specified speed.
mouse::drag_rel(500, 500); // Drags mouse to x, y relative to its position instantly.
mouse::slow_drag_rel(500, 500, Speed::Slower); // Drags mouse to x, y relative to its position with the specified speed.
mouse::click(Button::Left); // Performs a mouse click with the specified button.
mouse::down(Button::Left); // Performs a mouse down with the specified button.
mouse::up(Button::Left); // Performs a mouse up with the specified button.
mouse::scroll(ScrollAxis::Y, 10); // Scrolls x or y axis n times.
}
键盘
use rsautogui::{keyboard, keyboard::Vk};
fn main() {
keyboard::typewrite("Lorem ipsum!"); // Simulates typing the string provided.
// Print `A` using virtual key `Vk`
keyboard::key_down(Vk::Shift); // Presses specified key down.
keyboard::key_tap(Vk::A); // Performs specified key_down and key_up.
keyboard::key_up(Vk::Shift); // Releases specified key up.
// Print `A` with one line
keyboard::key_tap('A');
}
屏幕
use rsautogui::screen::{self, Rgba, DynamicImage};
fn main() {
let size: (u16, u16) = screen::size(); // Returns the width and height of primary screen.
let on_screen: bool = screen::on_screen(1920, 1080); // Verifies if specified x & y coordinates are present on primary screen.
let ss: DynamicImage = screen::screenshot(0, 0, 1920, 1080); // Returns screenshot of the primary screen.
screen::printscreen(ss, "./src/assets/screenshot.jpg"); // Saves the provided screenshot to a path with the specified filename and extension.
let loc: Option<(u16, u16)> = screen::locate_pixel(screen::Rgba([255, 255, 255, 255])); // Locates the first pixel color similar to the one specified and returns its coordinate.
let loc: Vec<(u16, u16)> = screen::locate_all_pixel(screen::Rgba([255, 255, 255, 255])); // Locates all pixel colors similar to the one specified and returns their coordinates.
let pixel: Rgba<u8> = screen::get_pixel(500, 500); // Get the pixel color on x, y coordinate.
}
您可以在 docs.rs
中阅读更多关于此 crate 的文档。
依赖关系
~13–42MB
~446K SLoC