Skip to main content

iMouse设备自动化控制库一个基于客户端-服务端架构的Python库,用于自动化控制iOS设备

Project description

🖱️ iMouse - iOS 设备自动化控制库

一个基于客户端-服务端架构的 Python 库,用于自动化控制 iOS 设备。
只适用于 iMouse XP 版,需配套专用硬件使用。


master;main

⚠️ 使用说明(请务必阅读)

  • 本项目仅适用于 iMouse XP 版,支持标准 iOS 无越狱环境直接控制,无需安装第三方插件和APP。
  • 必须使用配套的iMouse硬件才能完成控制操作。

官网地址 👉 https://www.imouse.cc
淘宝购买硬件 👉 https://imouse.taobao.com


🚀 快速开始

  • 使用前先使用pip安装imouse-py包
  • pip install imouse-py

使用api类基础接口调用

import imouse
from imouse.types import MouseSwipeParams

# 连接到 iMouse 服务端(默认地址为 localhost)
api = imouse.api(host="localhost")  # 获取api实例,所有iMouse提供的接口都在api实例里面调用

# 通过api类里面的方法执行鼠标操作
api.mouse_click("FA:9E:10:3A:FE:E8", "", 100, 100)  # 左键点击屏幕坐标 (100, 100)
api.mouse_swipe("FA:9E:10:3A:FE:E8", params=MouseSwipeParams(  # 向上滑动屏幕,从屏幕下百分之10滑动到屏幕的百分之90
    direction='up',  # 
    len=0.9
))

通过helper类更简单的调用(推荐使用)

console 提供的 API

提供对设备管理和全局操作的访问:

  • Device: 设备管理
  • AirPlay: 投屏连接和配置
  • USB: imouse硬件管理
  • Group: 分组管理
  • ImConfig: iMouse全局配置管理
  • User: iMouse账户管理
import imouse

# 连接到 iMouse 服务端(默认地址为 localhost)
api = imouse.api(host="localhost")  # 获取api实例

helper = imouse.helper(api)  # 获取helper类实例

console = helper.console  # 获取控制台实例
ret = console.device.list_by_id()  # 获取所有设备列表
print(ret)
# 投屏指定设备
ret = console.airplay.connect('FA:9E:10:3A:FE:E8,FD:9E:10:3A:FE:E0')
if ret:
    print('成功')
else:
    print(f'失败:{console.error_msg}')

# 断开指定设备投屏
ret = console.airplay.disconnect('FA:9E:10:3A:FE:E8,FD:9E:10:3A:FE:E0')
if ret:
    print('成功')
else:
    print(f'失败:{console.error_msg}')

# 投屏所有离线设备
ret = console.airplay.connect_all()
if ret:
    print('成功')
else:
    print(f'失败:{console.error_msg}')

device 提供的 API

提供对单个设备的控制:

  • Image: 设备图像操作,比如截图、找图、文字识别等
  • KeyBoard: 键盘操作
  • Mouse: 鼠标操作
  • Shortcut: 快捷指令操作
import imouse
from imouse.utils import file_to_base64
from imouse.types import MouseSwipeParams

# 连接到 iMouse 服务端(默认地址为 localhost)
api = imouse.api(host="localhost")  # 获取api实例

helper = imouse.helper(api)  # 获取helper类实例

device = helper.device('FA:9E:10:3A:FE:E8')  # 通过设备id获取设备实例

# 也可以通过devices方法获取所有实例列表
# device_list = helper.devices()
# device = device_list[0]

# 截图
ret = device.image.screenshot()
if ret:
    print('截图成功')
    with open('test.bmp', "wb") as f:
        f.write(ret)
else:
    print(f'截图失败:{device.error_msg}')

# 通过opencv找图
img_str = file_to_base64("test1.bmp")
ret = device.image.find_image_cv([img_str])
if len(ret) > 0:
    print(f"找图成功[{ret[0].centre[0]},{ret[0].centre[1]}]")
else:
    print(f'找图失败:{device.error_msg}')

# 向上滑动屏幕
ret = device.mouse.swipe(MouseSwipeParams(direction='up', len=0.9))  # 从屏幕下百分之10滑动到屏幕的百分之90
if ret:
    print('滑动成功')
else:
    print(f'滑动失败:{device.error_msg}')

iMouse事件处理

from typing import List
import imouse
from imouse.api import event
from imouse.models import DeviceInfo, UsbInfo, UserData, ImServerConfigData


@event.on("im_connect")
def im_connect(ver: str):
    print(f"[事件]连接内核成功: {ver}")


@event.on("im_disconnect")
def im_disconnect():
    print(f"[事件]与内核断开连接")


@event.on("dev_connect")
def dev_connect(device_info: DeviceInfo):
    print("[事件]有设备连接" + device_info.device_id)


@event.on("dev_disconnect")
def dev_disconnect(device_info: DeviceInfo):
    print("[事件]有设备断开连接->" + device_info.device_id)


@event.on("dev_rotate")
def dev_rotate(device_info: DeviceInfo):
    print("[事件]有设备发生旋转->" + device_info.device_id)


@event.on("dev_change")
def dev_change(device_info: DeviceInfo):
    print("[事件]有设备改变->" + device_info.device_id)


@event.on("dev_delete")
def dev_delete(deviceid_list: List[str]):
    print(f"[事件]有设备删除->{deviceid_list}")


@event.on("group_change")
def group_change(gid: str, name: str):
    print(f"[事件]有分组改变->{gid},{name}")


@event.on("group_change")
def group_change(gid: str, name: str):
    print(f"[事件]有分组改变->{gid},{name}")


@event.on("group_delete")
def group_delete(gid_list: List[str]):
    print(f"[事件]有分组删除->{gid_list}")


@event.on("usb_change")
def usb_change(usb_info: UsbInfo):
    print(f"[事件]有usb设备改变->{usb_info}")


@event.on("airplay_connect_log")
def airplay_connect_log(message: str):
    print(f"[事件]自动投屏日志->{message}")


@event.on("user_info")
def user_info(data: UserData):
    print(f"[事件]用户信息状态->{data}")


@event.on("im_log")
def im_log(message: str):
    print(f"[事件]iMouse事件->{message}")


@event.on("error_push")
def error_push(message: str, call_fun: str):
    print(f"[事件]iMouse错误日志->{message},{call_fun}")


@event.on("im_config_change")
def im_config_change(config: ImServerConfigData):
    print(f"[事件]iMouse内核配置改变->{config}")


@event.on("logout")
def logout():
    print(f"[事件]iMouse账号退出-")


@event.on("dev_sort_change")
def dev_sort_change(sort_index: int, sort_value: int):
    print(f"[事件]iMouse设备列表排序改变->{sort_index},{sort_value}")


api = imouse.api(host='192.168.9.9')

配置iMouse日志输出

import logging
from imouse.utils import logger

logger.configure(
    is_debug=True,  # 是否启用调试日志(False 时 info/debug 不输出)
    name='imouse',  # 日志名称(会影响 logger 名称和日志文件名)
    log_dir='logs',  # 日志目录(默认 logs 文件夹)
    log_level=logging.DEBUG,  # 日志等级
    log_show_thread_id=False,  # 是否显示线程 ID
    log_show_file_and_line=False  # 是否显示文件和行号
)

Project details


Download files

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

Source Distribution

imouse_py-0.0.3.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

imouse_py-0.0.3-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file imouse_py-0.0.3.tar.gz.

File metadata

  • Download URL: imouse_py-0.0.3.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.1

File hashes

Hashes for imouse_py-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a554f5d873727b65e0e4a1ea133b3cd0f70a3a501c2562aed0b4f846883e4bea
MD5 858d74f992d5065b6fa6d1f34f069eda
BLAKE2b-256 151404806b7a54630ac6c0b975113c763044747c96f4c09c0916ddb946fb9c3d

See more details on using hashes here.

File details

Details for the file imouse_py-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: imouse_py-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.1

File hashes

Hashes for imouse_py-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 257ae5e978d97524eefc12e2fd5c4482ba87a81e5e01c5eb3d712374119c5581
MD5 86212f794123f998b73abb856a36726e
BLAKE2b-256 83f44cf16464d533f9c2a5d80d8ad0e33e40e51921de4e0d9715c6cd417a7d2d

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