pyautogui笔记

https://blog.csdn.net/hfy1237/article/details/127960423

 

安装pyautogui库

pip install pyautogui -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 

# 获取像素的rgb值
pix = pyautogui.pixel(100, 200)

# 比较像素、rgb
if pyautogui.pixelMatchesColor(1698, 920, (4,5,7)):
    pass

# 点击指定坐标
pyautogui.click

# 鼠标按下左键,button默认是左键
pyautogui.click(button=left)
# 鼠标按下右键
pyautogui.click(button=right)
 

 

# 匹配像素点rgb色值
pyautogui.pixelMatchesColor ( 100, 200, ( 255, 255, 255 ), tolerance= 10)

 

# 保存截图
im = pyautogui.screenshot()
im.save(r"E:\pathtosave")

 

 

# 匹配像素点rgb色值
pyautogui.pixelMatchesColor ( 100, 200, ( 255, 255, 255 ), tolerance= 10)

 

 

# 识别屏幕上的指定图标,返回一个结果
# confidence是精确度,返回对象类型是location
pyautogui.locateOnScreen(path, confidence=0.8)

# 添加region参数,可以实现在指定的区域内进行匹配
left = 100
top = 100
width = 300
height = 200 location = pyautogui.locateOnScreen(region=(left, top, width, height),
path, confidence=0.8)


# 识别屏幕上的指定图标,返回多个结果 # 返回对象是location的生成器 pyautogui.locateAllOnScreen(item["path"], confidence=0.8)

 

# 移动鼠标到指定坐标(200,300)
pyautogui.moveTo(x=200,y=300)

 

posted @ 2023-05-12 19:38  光头小魔王  阅读(82)  评论(0)    收藏  举报