python adb

import os
import sys
from PIL import Image
from PIL import ImageDraw
import keyboard
import pyautogui
import time
import math
import pyautogui as pag
from math import cos, sin, pi

isdebug = 0
# 坐标渲染到截图片上 只是为了调试  上线可以截图生成图片调试注释掉


def shejijiancefn():
    gongji = [30, 30]
    pianyi = 20
    jineng1 = [130, 130]
    jineng2 = [230, 230]
    jineng3 = [330, 330]

    if isdebug == 1:
        screenShell = "adb shell /system/bin/screencap -p /sdcard/screenshot.jpg&adb pull /sdcard/screenshot.jpg i:/adb/screenshot.jpg"
        os.system(screenShell)
        img_src = Image.open('i:/adb/screenshot.jpg')
        img_src = img_src.convert("RGB")
        a = ImageDraw.ImageDraw(img_src)

        a.rectangle((gongji[0]-pianyi, gongji[1]-pianyi, gongji[0]+pianyi,
                    gongji[0]+pianyi), fill='black', outline='black', width=0)

        a.rectangle((jineng1[0]-pianyi, jineng1[1]-pianyi, jineng1[0] +
                    pianyi, jineng1[0]+pianyi), fill='red', outline='red', width=0)

        a.rectangle((jineng2[0]-pianyi, jineng2[1]-pianyi, jineng2[0] +
                    pianyi, jineng2[0]+pianyi), fill='blue', outline='blue', width=0)

        a.rectangle((jineng3[0]-pianyi, jineng3[1]-pianyi, jineng3[0]+pianyi,
                    jineng3[0]+pianyi), fill='green', outline='green', width=0)
        time_stamp = time.time()
        img_src.save("i:/adb/debug/catnew" +
                     str(round(time_stamp * 1000))+".jpg")

    tabshell = "adb shell input tap "+str(jineng2[0])+" "+str(jineng2[1])
    print(tabshell)
    os.system(tabshell)



def jiancepengzhuang():
    shejijiancefn()

keyboard.add_hotkey('x', jiancepengzhuang)
keyboard.wait()

 

posted @ 2022-06-13 19:35  newmiracle宇宙  阅读(39)  评论(0编辑  收藏  举报