清除编辑文字-ADB

Kri*_*ant 5 android adb android-framework android-shell

如何使用shell命令清除焦点编辑文本。

我试过了

adb shell input keyevent KEYCODE_CLEAR // Not worked 
adb shell input keyevent KEYCODE_DEL // Delete only one char
adb shell input keyevent KEYCODE_FORWARD_DEL // Not worked
Run Code Online (Sandbox Code Playgroud)

这样,我只能删除最多一个字符,有什么办法可以删除/清除重点突出的“编辑”文本。

Ped*_*ues 5

这对我有用:

function clear_input() {
    adb shell input keyevent KEYCODE_MOVE_END
    adb shell input keyevent --longpress $(printf 'KEYCODE_DEL %.0s' {1..250})
}
Run Code Online (Sandbox Code Playgroud)

然后:

clear_input
Run Code Online (Sandbox Code Playgroud)


小智 5

这将选择全部,然后退格。

input keycombination 113 29 && input keyevent 67
Run Code Online (Sandbox Code Playgroud)


小智 1

到目前为止,我发现的唯一方法是获取用于input swipe x y x y duration模拟长按的正确坐标。然后,这将突出显示 EditText 字段中的所有文本。然后,您可以发送您想要替换现有密钥的密钥。

我只是希望这adb shell input keyevent KEYCODE_CLEAR能清除该字段中的所有文本。如果有人能找到更好的方法,那就太好了,这会让事情变得容易得多。