android 系统按键,通过命令发送按键到Android系统



有时PAD或者VR机器上没有物理按键,但却想给应用发送这样的按键来测试应用程序是否OK,可以通过串口或者ADB执行以下命令达到目的:

input keyevent 键值名称

举几个例子:

模拟人的手指触摸HOME按键退到Launcher主界面:input keyevent HOME

模拟Android电视盒的遥控器发送MENU按键:input keyevent MENU

模拟物理键盘按向左键:input keyevent DPAD_LEFT

那后面的键值名称该写什么呢,看这个文件就好了:android/frameworks/base/core/java/android/view/KeyEvent.java,随便截取一段如下:  107     public static final int KEYCODE_1               = 8;  108     /** Key code constant: '2' key. */  109     public static final int KEYCODE_2               = 9;  110     /** Key code constant: '3' key. */  111     public static final int KEYCODE_3               = 10;  112     /** Key code constant: '4' key. */  113     public static final int KEYCODE_4               = 11;  114     /** Key code constant: '5' key. */  115     public static final int KEYCODE_5               = 12;  116     /** Key code constant: '6' key. */  117     public static final int KEYCODE_6               = 13;  118     /** Key code constant: '7' key. */  119     public static final int KEYCODE_7               = 14;  120     /** Key code constant: '8' key. */  121     public static final int KEYCODE_8               = 15;  122     /** Key code constant: '9' key. */  123     public static final int KEYCODE_9               = 16;  124     /** Key code constant: '*' key. */  125     public static final int KEYCODE_STAR            = 17;  126     /** Key code constant: '#' key. */  127     public static final int KEYCODE_POUND           = 18;  128     /** Key code constant: Directional Pad Up key.  129      * May also be synthesized from trackball motions. */  130     public static final int KEYCODE_DPAD_UP         = 19;  131     /** Key code constant: Directional Pad Down key.  132      * May also be synthesized from trackball motions. */  133     public static final int KEYCODE_DPAD_DOWN       = 20;  134     /** Key code constant: Directional Pad Left key.  135      * May also be synthesized from trackball motions. */  136     public static final int KEYCODE_DPAD_LEFT       = 21;  137     /** Key code constant: Directional Pad Right key.  138      * May also be synthesized from trackball motions. */  139     public static final int KEYCODE_DPAD_RIGHT      = 22;  140     /** Key code constant: Directional Pad Center key.  141      * May also be synthesized from trackball motions. */  142     public static final int KEYCODE_DPAD_CENTER     = 23;  143     /** Key code constant: Volume Up key.  144      * Adjusts the speaker volume up. */  145     public static final int KEYCODE_VOLUME_UP       = 24;  146     /** Key code constant: Volume Down key.  147      * Adjusts the speaker volume down. */  148     public static final int KEYCODE_VOLUME_DOWN     = 25;  149     /** Key code constant: Power key. */  150     public static final int KEYCODE_POWER           = 26;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值