这篇教程python实现电脑操控安卓手机写得很实用,希望能帮到您。 一、电脑下载并安装SDK Platform Tools

下载后的文件:platform-tools_r30.0.4-windows.zip(大约12M)
接着解压文件到指定目录

解压后的路径与文件,接着为工具目录添加系统环境变量

验证安装结果 
验证安装结果 手机连接电脑USB后执行adb devices 查看手机连接状态 查询已连接设备/模拟器:adb devices 此处连接手机,需要手机在开发者模式开启USB调试功能。顺便也开启模拟按键功能,后面会用到。 该命令经常出现以下问题: offline —— 表示设备未连接成功或无响应; device —— 设备已连接; no device —— 没有设备/模拟器连接; List of devices attached 设备/模拟器未连接到 adb 或无响应 简单获取手机屏幕坐标的方法方法1、进入手机的开发者模式,打开在手机上实时显示坐标的功能,长按屏幕位置自动显示坐标 方法2、使用android adb shell命令获取 # 截屏到手机adb shell screencap /sdcard/screen.png# 将手机上刚才的截图上传到电脑adb pull /sdcard/screen.png /Users/Administrator/Desktop/screen.png 从原始图片上,使用PS扣出自己想要的局部图片,然后使用下面的代码获取局部图片在原始图片上的坐标 不会使用PS,可以直接使用截图在原始图片上截图,但是没PS精细。 import aircv as ac# 根据图片在图片上查找坐标# imgsrc=原始图像,imgobj=待查找的图片,confidence=设置匹配系数def matchImg(imgsrc, imgobj, confidence=0.2): imsrc = ac.imread(imgsrc) imobj = ac.imread(imgobj) match_result = ac.find_all_template(imsrc, imobj, confidence) return match_resultif __name__ == '__main__': p = matchImg("C://Users//Administrator//Desktop//screen.png", "C://Users//Administrator//Desktop//daicha.png") print(p) 使用python操控手机import osimport timedef execute(cmd): adbstr = 'adb shell {}'.format(cmd) print(adbstr) os.system(adbstr)if __name__ == '__main__': while True: # 点击位置一 execute("input tap 350 2200") time.sleep(3) # 点击位置二 execute("input tap 970 135") time.sleep(5) android adb shell 常用命令android adb shell官方命令(英文)https://adbshell.com/ 以下命令来源: 1.模拟点击 adb shell input tap 100 100 2.滑动 adb shell input swipe x1 y1 x2 y2 adb input touchscreen swipe x1 y1 x2 y2 100adb shell input swipe 100 100 400 100 300 #左往右adb shell input swipe 400 100 100 100 300 #右往左adb shell input swipe 100 100 100 400 300 #上往下adb shell input swipe 100 400 100 100 300 #下往上adb shell input swipe 100 100 400 400 300 #上往下斜adb shell input swipe 400 400 100 100 300 #下往上斜 3.长按 adb shell input swipe 100 100 100 100 1000 //在 100 100 位置长按 1000毫秒adb shell input swipe 367 469 367 469 800 4.打印所有包名 adb shell pm list packages➜ ~ adb shell pm list packagespackage:com.huawei.floatMmspackage:com.android.defcontainerpackage:com.tencent.mm 5.打印制定包的apk路径 adb shell pm path com.android.phone➜ ~ adb shell pm path com.huawei.android.launcherpackage:/system/app/HwLauncher6.apk 6.删除制定包 adb shell pm clear com.test.abc 7.截图 adb shell screencap /sdcard/screen.pngadb pull /sdcard/screen.png #下载到本地 8.获取被点击的位置信息 adb shell getevent>/dev/input/event0 3 39 3e1/dev/input/event0 1 14a 1/dev/input/event0 1 145 1/dev/input/event0 3 35 406 //x坐标/dev/input/event0 3 54 1083 //y坐标/dev/input/event0 0 0 0/dev/input/event0 3 39 ffffffff/dev/input/event0 1 14a 0/dev/input/event0 1 145 0/dev/input/event0 0 0getevent -l -c 16输出所有event设备的基本信息add device 1: /dev/input/event2 name: "hi6421_on"could not get driver version for /dev/input/mouse0, Not a typewriteradd device 2: /dev/input/event4 name: "huawei,touchscreen"add device 3: /dev/input/event0 name: "mhl_rcp_dev"could not get driver version for /dev/input/mice, Not a typewriteradd device 4: /dev/input/event1 name: "hisi_gpio_key.14"add device 5: /dev/input/event3 name: "hi3630_hi6401_CARD Headset Jack"getevent -c 10 //输出10条信息后退出getevent -l //将type、code、value以对应的常量名称显示 9.打开对应的activity adb shell am start -n {包(package)名}/{包名}.{活动(activity)名称}adb shell am start com.songheng.eastnews/com.oa.eastfirst.activity.WelcomeActivity 10.获得当前活动窗口的信息,包名以及活动窗体 adb shell dumpsys window windows | grep mCurrent 11.包名管理命令,获得对应包名的对应apk路径 adb shell pm path com.migu.lobby 12.使用dumpsys命令可以查看Android手机当前正在运行的Activity adb shell dumpsys activity activities | findstr "Run" 13.使用 uiautomator dump 获取app上的页面元素 adb shell uiautomator dump /data/local/tmp/uidump.xmladb shell uiautomator dump /sdcard/dump.xml 14.下载文件 adb pull /sdcard/demo.mp4 15.上传文件 adb push test.apk /sdcard 16.息屏 adb shell input keyevent 26 17.keyevent adb shell input keyevent 20 #向下adb shell input keyevent 4 #返回adb shell input keyevent 3 #Homeadb shell input keyevent 6 #挂机adb shell input keyevent 84 #搜索adb shell input keyevent 26 #电源adb shell input keyevent 24 #音量+adb shell input keyevent 25 #音量- 18.输入框输入 adb shell input text "ANDROID" 19.利用无线来查看adb shell > adb tcpip 5555连接:> adb connect IP:5555 20.查看所有已经连接上的设备 21.安装卸载 adb install <apk文件路径>adb install -r <apk文件路径> 通过install命令来安装apk文件,-r参数可以重新安装某个应用并保留应用数据adb install -r ~/chrome.apk卸载应用:adb uninstall <软件名>adb uninstall -k < 软件名> 如果加 -k 参数,为卸载软件但是保留配置和缓存文件adb uninstall com.android.chrome 22.关机命令 到此这篇关于python实现电脑操控安卓手机的文章就介绍到这了,更多相关python电脑操控手机内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net! python 如何通过KNN来填充缺失值 Python 如何让特征值滞后一行 |