简体   繁体   English

尝试使用 python 和 adb 在命令提示符中使用变量

[英]Trying to use variable into command prompt using python and adb

import os
import random 
xpixel = random.randint(359,402) 
ypixel = random.randint(256,368) 
trest = random.randint(10,16)
print(trest)
time.sleep(trest)
print(xpixel)
print(ypixel)
os.system('cmd /k adb.exe shell input tap xpixel ypixel') <----I know this part is absolutly wrong but the concept is to be able to input those two numbers into command prompt some how.

I'm trying to click on a point in a screen using python/ adb.我正在尝试使用 python/adb 单击屏幕中的一个点。 I know how to generate the random number, and also the adb command.我知道如何生成随机数,也知道 adb 命令。 I just don't know how to transfer those variables and make them useful in command prompt.我只是不知道如何传输这些变量并使它们在命令提示符下有用。

While you can include variable values using f-strings虽然您可以使用 f 字符串包含变量值

f'cmd /k adb.exe shell input tap {xpixel} {ypixel}'

it might be better if instead of using adb and input you use a more specific library like AndroidViewClient/culebra or any other, to be able to do something.如果不使用adbinput ,而是使用更具体的库(如AndroidViewClient/culebra或任何其他库)来执行某些操作,可能会更好。 like this像这样

#! /usr/bin/env python3

import time
import random

from com.dtmilano.android.viewclient import ViewClient

device, serialno = ViewClient.connectToDeviceOrExit()
xpixel = random.randint(359,402)
ypixel = random.randint(256,368)
trest = random.randint(10,16)
print(trest)
time.sleep(trest)
print(xpixel)
print(ypixel)
device.touch(xpixel, ypixel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM