python 通过adb实现手机脚本

使用了aircv中的find_template方法从大图片中搜索小图片的坐标。用来点击按钮,查看是否满足状态等。 

import aircv as ac
import os

class Device:

    def __init__(self, id):
        self.id = id

    # 搜索返回图片位置
    def search_location(self, imsrc, imsch, threshold = 0.7):
        imsrc = ac.imread(imsrc)
        imsch = ac.imread(imsch)

        result = ac.find_template(imsrc, imsch, threshold=threshold)
        if not result:
            return result
        return result


    # 返回
    def back(self):
        os.system('adb -s ' + self.id + ' shell input keyevent 4')

    # 滑动
    def swipe(self):
        os.system('adb -s ' + self.id + ' shell input swipe 350 1580 350 680 200')


    # 截图
    def screen_cap(self):
        print(self)
        os.system('adb -s ' + self.id + ' shell screencap -p /sdcard/' + self.id + '.png')
        os.system('adb -s ' + self.id + '  pull /sdcard/' + self.id + '.png')


    def pic_in_screen(self, search_img, donotclick=False):
        if not donotclick:
            self.screen_cap()
        result = self.search_location(self.id + '.png', search_img)
        if not result:
            return False
        return result['result']

    # 点击
    def click(self, pos):
        os.system('adb -s ' + self.id + ' shell input  tap ' + str(pos[0]) + ' ' + str(pos[1]))

    # 点击图片
    def click_pic(self, path, donotclick=False):
        if not donotclick:
            self.screen_cap()
        result = self.search_location(self.id + '.png', path)
        if not result:
            return False
        self.click(result['result'])
        return True


# 返回当前连接的设备列表
def get_drive_list():
    devices = os.popen('adb devices')
    str_list = devices.read().split('\n')
    drive_list = []
    for i in str_list:
        if '\t' in i:
            drive_list.append(i.split('\t')[0])
    return drive_list

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwqqq2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值