美文网首页
adb命令给手机下发按键事件

adb命令给手机下发按键事件

作者: 似焰如火 | 来源:发表于2020-05-06 10:46 被阅读0次

1 键值的含义

Android 手机是支持按键控制的, 系统定义了各种按键所对应的key值, 从键值的名字来看,再结合注释,基本可以了解到它所代表的含义.

例如:
HOME 键, 表示手指触摸HOME按键退到Launcher主界面
DPAD_LEFT键, 表示物理键盘按向左键
DPAD_CENTER键, 表示按下物理键盘方向键中间的OK键

    /** Key code constant: Soft Left key.
     * Usually situated below the display on phones and used as a multi-function
     * feature key for selecting a software defined function shown on the bottom left
     * of the display. */
    public static final int KEYCODE_SOFT_LEFT       = 1;
    /** Key code constant: Soft Right key.
     * Usually situated below the display on phones and used as a multi-function
     * feature key for selecting a software defined function shown on the bottom right
     * of the display. */
    public static final int KEYCODE_SOFT_RIGHT      = 2;
    /** Key code constant: Home key.
     * This key is handled by the framework and is never delivered to applications. */
    public static final int KEYCODE_HOME            = 3;
    /** Key code constant: Back key. */
    public static final int KEYCODE_BACK            = 4;
    /** Key code constant: Call key. */
    public static final int KEYCODE_CALL            = 5;
    /** Key code constant: End Call key. */
    public static final int KEYCODE_ENDCALL         = 6;
    /** Key code constant: '0' key. */
    public static final int KEYCODE_0               = 7;
    /** Key code constant: '1' key. */
    public static final int KEYCODE_1               = 8;
    /** Key code constant: '2' key. */
    public static final int KEYCODE_2               = 9;
    /** Key code constant: '3' key. */
    public static final int KEYCODE_3               = 10;
    /** Key code constant: '4' key. */
    public static final int KEYCODE_4               = 11;
    /** Key code constant: '5' key. */
    public static final int KEYCODE_5               = 12;
    /** Key code constant: '6' key. */
    public static final int KEYCODE_6               = 13;
    /** Key code constant: '7' key. */
    public static final int KEYCODE_7               = 14;
    /** Key code constant: '8' key. */
    public static final int KEYCODE_8               = 15;
    /** Key code constant: '9' key. */
    public static final int KEYCODE_9               = 16;
    /** Key code constant: '*' key. */
    public static final int KEYCODE_STAR            = 17;
    /** Key code constant: '#' key. */
    public static final int KEYCODE_POUND           = 18;
    /** Key code constant: Directional Pad Up key.
     * May also be synthesized from trackball motions. */
    public static final int KEYCODE_DPAD_UP         = 19;
    /** Key code constant: Directional Pad Down key.
     * May also be synthesized from trackball motions. */
    public static final int KEYCODE_DPAD_DOWN       = 20;
    /** Key code constant: Directional Pad Left key.
     * May also be synthesized from trackball motions. */
    public static final int KEYCODE_DPAD_LEFT       = 21;
    /** Key code constant: Directional Pad Right key.
     * May also be synthesized from trackball motions. */
    public static final int KEYCODE_DPAD_RIGHT      = 22;
    /** Key code constant: Directional Pad Center key.
     * May also be synthesized from trackball motions. */
    public static final int KEYCODE_DPAD_CENTER     = 23;
    /** Key code constant: Volume Up key.
     * Adjusts the speaker volume up. */
    public static final int KEYCODE_VOLUME_UP       = 24;
    /** Key code constant: Volume Down key.
     * Adjusts the speaker volume down. */
    public static final int KEYCODE_VOLUME_DOWN     = 25;
    /** Key code constant: Power key. */
    public static final int KEYCODE_POWER           = 26;
    /** Key code constant: Camera key.
     * Used to launch a camera application or take pictures. */
    public static final int KEYCODE_CAMERA          = 27;
    /** Key code constant: Clear key. */
    public static final int KEYCODE_CLEAR           = 28;

2 使用方法

使用adb 命令下发按键事件, 链接手机后在终端输入如下命令:

adb shell input keyevent DPAD_DOWN
adb shell input keyevent DPAD_CENTER

相关文章

  • adb命令给手机下发按键事件

    1 键值的含义 Android 手机是支持按键控制的, 系统定义了各种按键所对应的key值, 从键值的名字来看,再...

  • 自动化工具-ADB

    ADB命令在手机端的自动化控制和处理 1. Android adb 模拟滑动 按键 点击事件 模拟事件全部是通过i...

  • adb命令模拟按键事件 KeyCode

    例子: //这条命令相当于按了设备的Backkey键 adb shell input keyevent 4 //可...

  • adb命令模拟按键事件 KeyCode

    //这条命令相当于按了设备的Backkey键 adb shell input keyevent 4 //可以解锁屏...

  • Adb快捷操作

    输入事件 //模拟输入“001”adb shell input text “001” //模拟home按键adb ...

  • Monkey

    Monkey:Android SDK自带的一个命令行工具,使用adb来运行它,向系统发送伪随机的用户事件流,如按键...

  • Android adb 使用详解(一)

    adb 源码 adb 命令 以下命令需要指定手机时, 添加-s [deviceNAme] 参数 基本命令 adb ...

  • 安卓ADB控制指令

    安卓ADB控制指令 可以通过如下ADB命令实现PC对Android手机的模拟输入,点击,滑动等事件,进而对Andr...

  • 王者荣耀简易刷冒险脚本

    不需要root,可以通过adb命令来让android手机触发点击事件首先本地安装adb工具,加入环境变量。然后让手...

  • adb命令发送文本

    场景:当需要向app文本框输入大量内容,或者由于兼容性问题导致手机按键失灵时,可以通过adb命令方式进行测试。 发...

网友评论

      本文标题:adb命令给手机下发按键事件

      本文链接:https://www.haomeiwen.com/subject/uheightx.html