【问题标题】:Is it possible to produce continuous swipe action on the touchscreen, with adb, on Android?是否可以在 Android 上使用 adb 在触摸屏上产生连续滑动动作?
【发布时间】:2014-10-19 11:15:00
【问题描述】:

我正在尝试在 adb 的帮助下重现滑动操作。 目前,此代码有效(用于滑动)

adb shell input touchscreen swipe 530 1420 530 1120
adb shell input touchscreen swipe 530 1120 830 1120

这是

adb shell input touchscreen swipe x1,y1, x2,y2

但它们是两次不连续的滑动。它相当于进行第一次滑动,将您的手从屏幕上移开,然后进行第二次滑动,依此类推..

我想通过单次滑动来实现这一点.. 就像,想象一个游戏,下面有热火,你必须将om-nom 拖过各种障碍物而不能将手指从om-nom.. 上面提到的 adb 滑动,可怜的om-nom 会掉进火里变成@ 987654324@。 :(

类似

adb shell input touchscreen swipe [(x1,y1, x2,y2), (x3,y3, x4,y4)...(xn-1,yn-1, xn,yn)]

如果不是 adb,还有其他选择吗?

【问题讨论】:

  • 与亚行?你能说出原因吗?
  • @pskink 因为我想在不接触手机的情况下做一些事情......只是一个实验。
  • 非常有趣,因为我正在尝试相同的方法,通过 ADB 进行屏幕解锁,但作为 @Ocelot 我得到 3 次不连续的滑动
  • @CorvenDallas 您可以为此使用unlock.sh 脚本。要获得正确的坐标,只需使用screencap 获取手机锁屏的屏幕截图。

标签: android adb swipe swipe-gesture


【解决方案1】:

您可以在亚行执行此操作。使用 getevent 记录您的手动输入:

adb shell getevent

或记录特定设备:

adb shell getevent /dev/input/eventx

然后模拟记录的输入:

adb shell sendevent /dev/input/eventx

【讨论】:

  • 很好的建议.. 立即尝试.. 已经能够模拟硬件按钮 :) .. 如果我得到所需的输出,将为您投票..
  • @Ocelot,你试过this way吗?使用geteventsetevent,我能够自动化操作/点击。
  • 我尝试了 HelgaM 的建议,但在锁定屏幕上似乎不起作用。我想模拟图案解锁。
  • @Ocelot 见this
【解决方案2】:
adb shell  "input touchscreen swipe 126 459 413 472 & input command touchscreen swipe 413 472 407 769"

您必须在 android 设备中运行 input 命令,以便在 input 之间继续交换添加 & 命令,示例如下:

adb shell "
   input touchscreen swipe 126 459 413 472 1000 & \ # 1th line 
   input touchscreen swipe 413 472 72  776 1000 & \ # 2th line
   input touchscreen swipe 72  776 407 769 1000 | echo done # 3th line" 


126 459   =   302 446   =   413 472
===================================
112 599   =   268 613   =   470 612
===================================
72  776   =   263 802   =   407 769

input touchscreen swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)

但需要在命令之间进行暂停或延迟(睡眠、等待),以便更精确地滑动。

【讨论】:

  • 虽然此代码 sn-p 可以解决问题,但 including an explanation 有助于提高您的回复质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
  • 对不起,我的英语太糟糕了,但我肯定会在未来尝试评论我的答案
  • 您的帖子底部有一个edit link。您可以使用它来扩展您的答案。
  • 此解决方案将导致同时执行 3 次滑动,而不是连续执行。睡眠命令没有任何帮助。
【解决方案3】:

如果您的用例允许在 2000 毫秒内进行慢速滑动,那么滑动几乎就像拖动一样。

shell input touchscreen swipe x1,y1, x2,y2 [duration]

【讨论】:

    【解决方案4】:

    这行得通

    $adb shell input touchscreen swipe x1 y1 &amp; adb shell input touchescreen x2 y2 &amp; adb shell input touchescreen x3 y3

    【讨论】:

      【解决方案5】:

      我认为这将是一个不错的选择

      for i in {1..5}; do adb shell input touchscreen swipe 530 1420 530 1120; adb shell input touchscreen swipe 530 1120 830 1120; done
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多