
测试PC安装ADB调试工具,用于和Android设备交互,主要完成截图,截图下载,进行按压屏幕模拟。
下载后放到合适的位置解压,不要安装。在Win10中,系统目录和之前有所不同,所以旧的安装方法是无效的。

Android设备通过USB连接到测试PC,Android 设备开启调试模式,需要保证ADB能正常和Android连接。
在命令行中进入解压后的目录,输入Adb devices如果看到CMD显示一串字符,后面还有一个“device”的字样,那就说明安卓机已经成功以USB调试的形式连接到了Win10中。

Android 进入微信跳一跳小程序并开始游戏。完整源码以及更多的游戏源码分享,戳这里
在PC上运行脚本程序,脚本程序正常运行,输入y,开始自动游戏。

主要代码
def _get_screen_size():
"""
获取手机屏幕分辨率
:return:
"""
size_str = os.popen('adb shell wm size').read()
print(size_str)
if not size_str:
print('请安装 ADB 及驱动并配置环境变量')
sys.exit()
m = re.search(r'(\d+)x(\d+)', size_str)
if m:
return "{height}x{width}".format(height=m.group(2), width=m.group(1))
def init():
"""
初始化
:return:
"""
# 获取屏幕分辨率
screen_size = _get_screen_size()
config_file_path = 'config/{0}/config.json'.format(screen_size)
print(config_file_path)
if os.path.exists(config_file_path):
with open(config_file_path, 'r') as f:
print("Load config file from {}".format(config_file_path))
return json.load(f)
else:
with open('config/default.json', 'r') as f:
print("Load default config")
return json.load(f)
def get_screenshot():
global SCREENSHOT_WAY
if SCREENSHOT_WAY == 2 or SCREENSHOT_WAY == 1:
process = subprocess.Popen('adb shell screencap -p', shell=True, stdout=subprocess.PIPE)
screenshot = process.stdout.read()
if SCREENSHOT_WAY == 2:
binary_screenshot = screenshot.replace(b'\r\n', b'\n')
else:
binary_screenshot = screenshot.replace(b'\r\r\n', b'\n')
with open('autojump.png', 'wb') as f:
f.write(binary_screenshot)
elif SCREENSHOT_WAY == 0:
os.system('adb shell s creencap -p /sdcard/autojump.png')
os.system('adb pull /sdcard/autojump.png .')
def check_screenshot():
global SCREENSHOT_WAY
if os.path.isfile('autojump.png'):
os.remove('autojump.png')
if SCREENSHOT_WAY < 0:
print('暂不支持当前设备')
sys.exit()
get_screenshot()
try:
Image.open('autojump.png').load()
exc

这篇博客介绍了如何利用Python和ADB调试工具在PC上自动化玩微信跳一跳小游戏。首先,需要设置ADB与Android设备连接,确保调试模式开启。接着,运行脚本程序,输入确认指令即可开始自动游戏。
最低0.47元/天 解锁文章
1913

被折叠的 条评论
为什么被折叠?



