ADB/Python中的滑动释放

3

我正在尝试自动化一个快速从x1,y1滑到x2,y2的滑动输入,然后在最终位置停留5秒钟并释放屏幕...

如何使用ADB在Python中完成此操作?

我已经尝试过这个,但它只是缓慢地滑动了5秒钟,而不是快速地滑动到终点,然后保持滑动状态5秒钟...

device.shell('input touchscreen swipe 540 1000 540 1700 5000')
2个回答

1

使用 AndroidViewClient/culebraCulebraTester-public 后端,您可以像这样做

#! /usr/bin/env python3

from com.dtmilano.android.viewclient import ViewClient

s = []
for i in range(1000, 1700, 100):
    s.append((540, i))
s.extend([(540, 1700)] * 250)


helper = ViewClient.view_client_helper()

# Performs a swipe from one coordinate to another using the number of steps to determine smoothness and speed.
# Each step execution is throttled to 5ms per step.
helper.ui_device.swipe(segments=s, segment_steps=2)

我猜这样做是你想要的。也许你需要调整一些参数。

请注意,由于所有步骤的时间相等,你需要多次将最后一个点添加到分段列表中,这与adb不完全相同。

它基于示例:https://github.com/dtmilano/AndroidViewClient/blob/master/examples/helper/swipekeep-swipe.gif)。


0
尝试使用motionevent而不是swipe
def motionevent(action, x, y):
    device.shell(f"input motionevent {action} {x} {y}") 
    
def unlock_phone():
    motionevent("DOWN", x1, y1)
    motionevent("MOVE", x, y)   # some point between start -> end, as you wish
    motionevent("MOVE", x, y)   # some point between start -> end, as you wish
    motionevent("MOVE", x2, y2)
    for i in range(10):
        time.sleep(0.2)
        motionevent("MOVE", x2, y2) # hold here
    motionevent("UP", x2, y2)   # release

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接