上代码
from PIL import Image
import os
def getPngPix(x,y):
pngPath = r"D:\adb\screen.png"
pixelX = x
pixelY = y
img_src = Image.open(pngPath)
img_src = img_src.convert('RGB')
str_strlist = img_src.load()
data = str_strlist[pixelX, pixelY]
img_src.close()
return data
while True:
os.system(r"D:\adb\adb.exe shell screencap /sdcard/screen.png")
os.system(r"D:\adb\adb.exe pull /sdcard/screen.png D:\adb")
if getPngPix(480,2154) == (250, 157, 59): #扫描红包颜色
os.system(r"D:\adb\adb.exe shell input tap 580 2041") #点击红包
os.system(r"D:\adb\adb.exe shell screencap /sdcard/screen.png")
os.system(r"D:\adb\adb.exe pull /sdcard/screen.png D:\adb")
os.system(r"D:\adb\adb.exe shell input tap 557 1489") #点击开红包按钮
while True:
os.system(r"D:\adb\adb.exe shell screencap /sdcard/screen.png")
os.system(r"D:\adb\adb.exe pull /sdcard/screen.png D:\adb")
if getPngPix(544,321) == (240, 206, 111):
print("抢到红包")
os.system(r"D:\adb\adb.exe shell input tap 34 165") #关闭红包界面
break
else:
pass
else:
pass
程序应用在HUAWEI Mate 30上,有需要的自行修改,如果也是HUAWEI Mate 30的可以直接使用