android sentevent,android sendevent模拟滑动点击事件

本文介绍了如何通过adbshellinput命令进行模拟事件,如swipe、tap和keyevent,详细解释了home键、back键的使用,并给出了不同屏幕操作和场景下的解决方案,如陀螺仪翻页、屏幕滑动等。还提到了Android Ring SDK的事件注入和权限管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

adb shell input swipe 250 250 300 300

模拟事件全部是通过input命令来实现的,首先看一下input命令的使用:

usage: input ...

input text input keyevent input tap input swipe

keyevent指的是android对应的keycode,比如home键的keycode=3,back键的keycode=4.

具体请查阅 http://blog.youkuaiyun.com/huiguixian/article/details/8550170

然后使用的话比较简单,比如想模拟home按键:

adb shell input keyevent 3

请查阅上述文章,根据具体keycode编辑即可。

关于tap的话,他模拟的是touch屏幕的事件,只需给出x、y坐标即可。

此x、y坐标对应的是真实的屏幕分辨率,所以要根据具体手机具体看,比如你想点击屏幕(x, y) = (250, 250)位置:

adb shell input tap 250 250

关于swipe同tap是一样的,只是他是模拟滑动的事件,给出起点和终点的坐标即可。例如从屏幕(250, 250), 到屏幕(300, 300)即

adb shell input swipe 250 250 300 300

在项目中实现陀螺仪翻页的解决策略

竖屏

向右滑 :input swipe 50 1000 650 1000 ->

向左滑: input swipe 650 1000 50 1000

横屏

默认点击屏幕在横屏状态下的中心位置 input tap 627 283 (可以完成例如在相册页面的)

向右滑 :input swipe 600 300 800 300 -> (适用于小范围的移动。 例如相册的展示页面)

向左滑 :input swipe 800 300 60 300

向右滑 :input swipe 200 300 1200 300 -> (适用于大范围的移动。 例如相册的单张浏览模式)

向右滑 :input swipe 1200 300 200 300

superbar中使用命令在不申请root的条件下打开设备文件节点的权限

打开设备文件节点的权限:chmod 666 /dev/input/*

查看设备文节点的权限: ll /dev/input

android RingSDK 的事件注入

https://code.google.com/p/android-event-injector/

ps:在没有OTG线的情况下连接电脑,通过命令打开任意的app

adb shell am start com.wormhole.glass1/com.wormhole.glass.MainActivit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值