linux /dev/input/event 与 getEvent

最近在研究key事件从底层到上层的流程.发现新添加Key时候引起了一下bug.在此记录一下.

1.熟悉adb shell getevent 命令

HP-ProBook-640-G2:~/local$ adb shell getevent -p
add device 1: /dev/input/event2
  name:     "mtk-kpd"
  events:
    KEY (0001): 0002  0003  0004  0005  0006  0007  0008  0009
                000a  000b  001c  0067  0069  006a  006c  006f
                0072  0073  0074  008b  009e  00d3  00d4  00e3
                00e7  020b
  input props:
    <none>
add device 2: /dev/input/event3
  name:     "hwmdata"
  events:
    REL (0002): 0001  0002
  input props:
    <none>
add device 3: /dev/input/event1
  name:     "ACCDET"
  events:
    KEY (0001): 0072  0073  00a4  0246
  input props:
    <none>
add device 4: /dev/input/event0
  name:     "hall"
  events:
    KEY (0001): 0035  00fc
    SW  (0005): 0000
  input props:
    <none>

1.1可以看出add device 对应的是/dev/input/event. name: 对应该的名字很重要,后面keylayout 会用到.events:里面有定义的key值.

注:key是底层工程师注册到device上的,如果keylayout文件的命名和device对应的name不一致,则.kl文件将无效

1.2在手机目录下存在keylayout文件可以将Key值定义在此处.

shell@sr6731_kaie_c_k:/system/usr/keylayout $

mtk-kpd.kl
qwerty.kl

ACCDET.kl
AVRCP.kl
Generic.kl

注:此处的命名对应所在设备event的name.

adb 模拟按键事件可以使用sendevent

eg:下面是我写的一个脚本

#/bash
#send_event.sh:

adb root
adb remount
 
adb shell sendevent /dev/input/event0  0001 0028 00000001
adb shell sendevent /dev/input/event0  0000 0000 00000000
adb shell sendevent /dev/input/event0  0001 0028 00000000
adb shell sendevent /dev/input/event0  0000 0000 00000000
echo 'Done!'

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值