Skip to main content

一个基于 **Rust + PyO3** 封装的高性能鼠标与键盘控制库,为 Python 提供了与人类操作无异的自动化输入功能。

Project description

rustautogui_py

一个基于 Rust + PyO3 封装的高性能鼠标与键盘控制库,
为 Python 提供了与人类操作无异的自动化输入功能。

本项目基于 rustautogui 实现,
相比纯 Python 的 pyautogui,具有以下优势:

  • 🚀 性能更高:底层使用 Rust 实现系统调用;
  • 🧠 更安全:内存与线程安全;
  • 🖱️ 功能全面:支持鼠标移动、拖拽、滚轮、键盘输入、多键组合;
  • 🧩 Python 无缝集成:通过 PyO3 封装,可直接在 Python 中调用。

🧰 安装

从 PyPI

pip install rustautogui-py

🧪 使用示例

from rustautogui_py import MouseKeyBoardController
import time

gui = MouseKeyBoardController()

# 获取屏幕大小
w, h = gui.get_screen_size()
print(f"Screen: {w}x{h}")

# 获取当前鼠标位置
x, y = gui.get_mouse_position()
print(f"Mouse: ({x}, {y})")

# 移动鼠标到屏幕中央
gui.move_mouse_to_pos(w // 2, h // 2, 0.5)

# 执行点击
gui.left_click()
time.sleep(0.2)
gui.double_click()

# 模拟键盘输入
gui.keyboard_input("Hello Rust + Python!")
time.sleep(0.5)

# 组合键操作
gui.keyboard_multi_key("ctrl", "shift", "n")  # Ctrl+Shift+N
gui.keyboard_multi_key("ctrl", "c")           # Ctrl+C
gui.keyboard_multi_key("alt", "f4")           # Alt+F4

🖱️支持功能一览

方法名 功能说明 参数 返回值
get_screen_size() 获取屏幕分辨率 (width, height)
get_mouse_position() 获取鼠标坐标 (x, y)
move_mouse_to_pos(x, y, duration) 将鼠标移动到指定坐标 x: u32, y: u32, duration: f32 None
move_mouse(x, y, duration) 相对移动鼠标 x: i32, y: i32, duration: f32 None
drag_mouse_to_pos(x, y, duration) 拖拽至指定坐标 同上 None
drag_mouse(x, y, duration) 拖拽至相对偏移 同上 None
click(button) 点击鼠标键 "left", "right", "middle" None
click_down(button) 按下鼠标键 同上 None
click_up(button) 释放鼠标键 同上 None
left_click() 左键单击 None
right_click() 右键单击 None
double_click() 左键双击 None
middle_click() 中键点击 None
scroll_up(intensity) 向上滚动滚轮 intensity: u32 None
scroll_down(intensity) 向下滚动滚轮 intensity: u32 None
scroll_left(intensity) 向左滚动 intensity: u32 None
scroll_right(intensity) 向右滚动 intensity: u32 None
key_down(key) 按下键盘按键 key: str None
key_up(key) 松开键盘按键 key: str None
keyboard_input(str) 输入字符串 str: &str None
keyboard_command(command) 特殊命令(如回车、ESC) command: &str None
keyboard_multi_key(args) 同时按下多个按键 ["ctrl", "shift", "n"] None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rustautogui_py-0.1.1-cp312-cp312-win_amd64.whl (162.2 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file rustautogui_py-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for rustautogui_py-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 323b1986e3a029ac0fda7166570b5421def337884c64c3c33134428611a90c71
MD5 d908414d0d50014514b16cd7688407da
BLAKE2b-256 8f44f108b24eaa2422d317baf2adcaff7b83dd9d12d130f23ca01fb30aea5d73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page