前置环境准备:
使用mumu12模拟器 自行在模拟器中搜索安装小猿口算
pytesseract需要在github仓库下载最新win安装包
https://github.com/UB-Mannheim/tesseract/wiki
其它包体直接pip安装即可
全部代码:
print_mouth_location.py
实际上print_mouth_location.py只是方便大家边移动鼠标边打印屏幕坐标 方便确定自己的截屏位置和鼠标所在像素点的RGB 并不涉及脚本逻辑
from PIL import ImageGrab
from pynput import mouse
def on_move(x, y):
# 处理鼠标移动事件,输出当前坐标
print(f"Mouse moved to ({x}, {y}).")
def on_click(x, y, button, pressed):
# 当鼠标点击事件发生时,输出点击的信息
color = get_pixel_color(x, y)
if not pressed:
print(f"Mouse clicked at ({x}, {y}) with {button},Color: RGB{color}")
# 当鼠标点击事件发生且松开时,退出监听
return False
def on_scroll(x, y, dx, dy):
# 当鼠标滚轮事件发生时,输出滚轮的信息
print(f"Mouse scrolled at ({x}, {y}) with delta ({dx}, {dy})")
def get_pixel_color(x, y):
# 捕获鼠标位置的像素颜色
pixel_color = ImageGrab.grab(bbox=(x, y, x+1, y+1)).getpixel((0, 0))
return pixel_color
# 设置鼠标监听器
with mouse.Listener(
on_move=on_move,
on_click=on_click,
on_scroll=on_scroll) as listener:
listener.join()
main.py
这边是核心逻辑 话不多说 都在注释中
import py