基本命令

  adb 模拟按键输入的命令主要通过 input 进行

Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
gesture
touchscreen
gamepad The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)

参数解释

常用命令

物理键:

adb shell input keyevent 26 # 电源键
adb shell input keyevent 82 # 菜单键
adb shell input keyevent 3 # HOME 键
adb shell input keyevent 4 # 返回键
adb shell input keyevent 24 # 音量+
adb shell input keyevent 25 # 音量-
adb shell input keyevent 164 # 静音 

媒体控制

adb shell input keyevent 85 # 播放/暂停
adb shell input keyevent 86 # 停止播放
adb shell input keyevent 87 # 播放下一首
adb shell input keyevent 88 # 播放上一首
adb shell input keyevent 126 # 恢复播放
adb shell input keyevent 127 # 暂停播放

点亮/熄灭屏幕

  可以通过上 模拟电源键 来切换点亮和熄灭屏幕,但如果明确地想要点亮或者熄灭屏幕,那可以使用如下方法。

adb shell input keyevent 224 # 点亮屏幕
adb shell input keyevent 223 # 熄灭屏幕

触击屏幕

adb shell input tap <X> <Y> # x,y为坐标位置

滑动屏幕

  划动屏幕用到了 swipe 命令,它有四个参数,分别是起始点x坐标 起始点y坐标 结束点x坐标 结束点y坐标。

  如果锁屏没有密码,是通过滑动手势解锁,那么可以通过 input swipe 来解锁。

# 四个参数:起始点x坐标 起始点y坐标 结束点x坐标 结束点y坐标。
adb shell input swipe 300 1000 300 500 # 向上滑动
adb shell input swipe 300 100 300 1000 # 向下滑动
adb shell input swipe 1000 500 200 500 # 向左滑动
adb shell input swipe 200 500 1000 500 # 向右滑动

输入文本

  在焦点处于某文本框时,可以通过 input 命令来输入文本。

adb shell input text hello # 输入hello

keyevent 命令大全

  官方文档地址:https://developer.android.com/reference/android/view/KeyEvent

  中文keycode大全:adb——keyevent命令大全

ADB——模拟手机按键输入的更多相关文章

  1. Helium文档5-WebUI自动化-press模拟键盘按键输入技巧

    前言 press方法是用来模拟键盘按键输入,可以组合使用,来模拟键盘输入,解决一些难定位的元素 入参介绍 以下是press源码中的函数介绍 def press(key):  :入参 :param ke ...

  2. Android adb 模拟滑动 按键 点击事件

    模拟事件全部是通过input命令来实现的,首先看一下input命令的使用: usage: input ... input text <string>       input keyeven ...

  3. Android应用程序模拟手机按键

    记得以前在做一个C++项目时,需要在某一步操作之后人为用代码模拟敲键盘上的回车键(Enter)效果. 出于好奇,这几天研究了一下Android中手机(或平板)上各种按键的键值.模拟方法及最终效果. 1 ...

  4. 【python-appium】模拟手机按键搜索异常

    执行代码的过程中运行self.driver.press_keycode(84)设备没反映,则需要关闭#desired_caps["unicodeKeyboard"] = " ...

  5. Python脚本控制的WebDriver 常用操作 <十二> send_keys模拟按键输入

    下面将使用WebDriver中的send_keys来模拟键盘按键输入 测试用例场景 send_keys方法可以模拟一些组合键操作: ctrl+a ctrl+c ctrl+v 等. 另外有时候我们需要在 ...

  6. adb命令模拟按键输入keycode

    adb命令模拟按键输入keycode 2017年05月18日 14:57:32 阅读数:1883 例子: //这条命令相当于按了设备的Backkey键 adb shell input keyevent ...

  7. adb shell命令模拟按键/输入input使用keycode 列表详解

    在adb shell里有一个非常使用的命令,模拟按键输入,这里首先不要理解为是键盘的模拟按键,下面命令的使用和键值做一个详解. input命令格式 adb shell input keyevent & ...

  8. linux下如何模拟按键输入和模拟鼠标【转】

    转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...

  9. Python 脚本利用adb 进行手机控制

    相关参考:https://www.cnblogs.com/bravesnail/articles/5850335.html 一.  adb 相关命令: 1. 关闭adb服务:adb kill-serv ...

随机推荐

  1. 三目算法、if/else,switch/case运用

    //输入学生的成绩,判断考试是否及格,及格6大于等于0 //第一种写法:三目运算 大多用于单独判断是否满足某个条件 import java.util.Scanner; public class Hel ...

  2. 通过mysqlbinlog 恢复数据

    前提数据库开启了bin_log记录日志. 查看日志 刷新日志 flush logs; 再次查看 show binary logs; 向表中插入一条数据 现在执行delete误操作,删除所有的数据. d ...

  3. intellij idea创建maven项目

    1.安装好JDK,Tomcat,安装好maven: 2.配置maven全局变量:file->Other Settings ->Default Settings->Build,Exec ...

  4. shell入门(二):()、(())、[]、[[]]、{}

    1.() 命令组. 括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号’;’隔开,最后一个命令可以没有分号,各命令和括号之间不必有空格. ...

  5. python第九天(9-33)

    一:进程 进程概念 进程就是一个程序运行在一个数据集上的一次动态执行过程 进程一般由程序,数据集,进程控制块组成 进程控制块: 进程控制块用来记录进程的外部特征,描述进程的执行变化过程,系统可以利用它 ...

  6. [转]安装v2ray,部署手机电脑***

    https://www.coding996.com/digitalocean-build-v2ray-0-1/https://blog.verkey.org/209.html 环境信息 服务器系统:C ...

  7. uiautomator设备和选择器~Python详解

    1.设备对象 引入uiautomator,获取设备对象<所谓设备对象可理解为:Android模拟器或者真机> 语法:from uiautomator import device as d ...

  8. java实验5

    实验一要求: 两人一组结对编程: 参考http://www.cnblogs.com/rocedu/p/6766748.html#SECDSA 结对实现中缀表达式转后缀表达式的功能 MyBC.java ...

  9. Python金融大数据分析PDF

    Python金融大数据分析(高清版)PDF 百度网盘 链接:https://pan.baidu.com/s/1CF2NhbgpMroLhW2sTm7IJQ 提取码:clmt 复制这段内容后打开百度网盘 ...

  10. 做rl_abs过程中遇到的问题

    问题一 运行 train_abstractor.py就出现这个问题 nohup: ignoring input start training with the following hyper-para ...