关于pyautoguimac的信息

## pyautoguimac:让你的Mac自动化起来### 简介pyautoguimac 是 Python 的一个第三方库,用于在 macOS 系统上模拟鼠标和键盘操作,实现自动化任务。它基于 pyautogui 库,并针对 macOS 系统进行了一些优化和扩展。### 主要功能

1. 鼠标控制

移动鼠标: `pyautoguimac.moveTo(x, y)`

获取鼠标位置: `pyautoguimac.position()`

点击鼠标: `pyautoguimac.click(x, y, button='left')`

双击鼠标: `pyautoguimac.doubleClick(x, y, button='left')`

右击鼠标: `pyautoguimac.rightClick(x, y)`

滚动鼠标滚轮: `pyautoguimac.scroll(clicks, x=None, y=None)`

拖拽鼠标: `pyautoguimac.dragTo(x, y, button='left', duration=0.0)`

2. 键盘控制

按下按键: `pyautoguimac.keyDown(key)`

释放按键: `pyautoguimac.keyUp(key)`

输入字符: `pyautoguimac.press(keys)`

输入文本: `pyautoguimac.typewrite(text, interval=0.0)`

热键操作: `pyautoguimac.hotkey(

args,

kwargs)`

3. 屏幕截图

截取全屏: `pyautoguimac.screenshot()`

截取指定区域: `pyautoguimac.screenshot(region=(x1, y1, x2, y2))`

4. 图像识别

在屏幕上查找图片: `pyautoguimac.locateOnScreen(image, confidence=0.999)`

获取图片在屏幕上的中心坐标: `pyautoguimac.center(location)`### 安装使用 pip 安装:```bash pip install pyautoguimac ```### 使用示例

1. 自动打开应用程序并输入文本:

```python import pyautoguimac# 打开 Safari 浏览器 pyautoguimac.hotkey('command', 'space') pyautoguimac.typewrite('Safari\n', interval=0.25)# 在地址栏输入网址 pyautoguimac.typewrite('https://www.google.com\n', interval=0.25)# 在搜索框输入文字 pyautoguimac.typewrite('Hello World!\n', interval=0.25) ```

2. 定位图片并点击:

```python import pyautoguimac# 加载图片 image = pyautoguimac.screenshot('button.png')# 在屏幕上查找图片 location = pyautoguimac.locateOnScreen(image)# 点击图片中心 if location:x, y = pyautoguimac.center(location)pyautoguimac.click(x, y) ```### 注意事项

pyautoguimac 需要获取系统权限才能控制鼠标和键盘,请在使用前授权。

使用图像识别功能时,请确保图片清晰可见,并设置合适的置信度。

为了避免脚本失控,建议在代码中添加适当的延时。### 总结pyautoguimac 是一个方便易用的 macOS 自动化工具,可以帮助你轻松实现各种重复性任务的自动化。

pyautoguimac:让你的Mac自动化起来

简介pyautoguimac 是 Python 的一个第三方库,用于在 macOS 系统上模拟鼠标和键盘操作,实现自动化任务。它基于 pyautogui 库,并针对 macOS 系统进行了一些优化和扩展。

主要功能**1. 鼠标控制*** 移动鼠标: `pyautoguimac.moveTo(x, y)` * 获取鼠标位置: `pyautoguimac.position()` * 点击鼠标: `pyautoguimac.click(x, y, button='left')` * 双击鼠标: `pyautoguimac.doubleClick(x, y, button='left')` * 右击鼠标: `pyautoguimac.rightClick(x, y)` * 滚动鼠标滚轮: `pyautoguimac.scroll(clicks, x=None, y=None)` * 拖拽鼠标: `pyautoguimac.dragTo(x, y, button='left', duration=0.0)`**2. 键盘控制*** 按下按键: `pyautoguimac.keyDown(key)` * 释放按键: `pyautoguimac.keyUp(key)` * 输入字符: `pyautoguimac.press(keys)` * 输入文本: `pyautoguimac.typewrite(text, interval=0.0)` * 热键操作: `pyautoguimac.hotkey(*args, **kwargs)`**3. 屏幕截图*** 截取全屏: `pyautoguimac.screenshot()` * 截取指定区域: `pyautoguimac.screenshot(region=(x1, y1, x2, y2))`**4. 图像识别*** 在屏幕上查找图片: `pyautoguimac.locateOnScreen(image, confidence=0.999)` * 获取图片在屏幕上的中心坐标: `pyautoguimac.center(location)`

安装使用 pip 安装:```bash pip install pyautoguimac ```

使用示例**1. 自动打开应用程序并输入文本:**```python import pyautoguimac

打开 Safari 浏览器 pyautoguimac.hotkey('command', 'space') pyautoguimac.typewrite('Safari\n', interval=0.25)

在地址栏输入网址 pyautoguimac.typewrite('https://www.google.com\n', interval=0.25)

在搜索框输入文字 pyautoguimac.typewrite('Hello World!\n', interval=0.25) ```**2. 定位图片并点击:**```python import pyautoguimac

加载图片 image = pyautoguimac.screenshot('button.png')

在屏幕上查找图片 location = pyautoguimac.locateOnScreen(image)

点击图片中心 if location:x, y = pyautoguimac.center(location)pyautoguimac.click(x, y) ```

注意事项* pyautoguimac 需要获取系统权限才能控制鼠标和键盘,请在使用前授权。 * 使用图像识别功能时,请确保图片清晰可见,并设置合适的置信度。 * 为了避免脚本失控,建议在代码中添加适当的延时。

总结pyautoguimac 是一个方便易用的 macOS 自动化工具,可以帮助你轻松实现各种重复性任务的自动化。

标签列表