天天看點

N-android輸入系統1

1、檢視輸入裝置節點資訊

adb shell cat /proc/bus/input/devices

I: Bus=0019 Vendor=0000 Product=0000 Version=0000   

N: Name="ACCDET"                                    

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input0              

U: Uniq=                                            

H: Handlers=gpufreq_ib event0                       

B: PROP=0                                           

B: EV=3                                             

B: KEY=40 0 0 0 0 0 0 1000000000 c000000000000 0    

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="fpsensor"                                  

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input1              

U: Uniq=                                            

H: Handlers=gpufreq_ib event1                       

B: PROP=0                                           

B: EV=3                                             

B: KEY=40008000 800010 0                            

I: Bus=0019 Vendor=2454 Product=6500 Version=0010   

N: Name="mtk-kpd"                                   

P: Phys=                                            

S: Sysfs=/devices/soc/10003000.keypad/input/input2  

U: Uniq=                                            

H: Handlers=gpufreq_ib event2                       

B: PROP=0                                           

B: EV=3                                             

B: KEY=1c004000000000 0                             

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="hwmdata"                                   

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input3              

U: Uniq=                                            

H: Handlers=gpufreq_ib event3                       

B: PROP=0                                           

B: EV=5                                             

B: REL=6                                            

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="m_alsps_input"                             

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input4              

U: Uniq=                                            

H: Handlers=gpufreq_ib event4                       

B: PROP=0                                           

B: EV=d                                             

B: REL=6                                            

B: ABS=101                                          

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="m_acc_input"                               

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input5              

U: Uniq=                                            

H: Handlers=gpufreq_ib event5                       

B: PROP=0                                           

B: EV=d                                             

B: REL=c1                                           

B: ABS=107                                          

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="m_mag_input"                               

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input6              

U: Uniq=                                            

H: Handlers=gpufreq_ib event6                       

B: PROP=0                                           

B: EV=d                                             

B: REL=3c9                                          

B: ABS=17f                                          

I: Bus=0000 Vendor=0000 Product=0000 Version=0000   

N: Name="mtk-tpd"                                   

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input7              

U: Uniq=                                            

H: Handlers=gpufreq_ib event7                       

B: PROP=2                                           

B: EV=b                                             

B: KEY=400 0 0 100040000800 0 0                     

B: ABS=263000001000003                              

I: Bus=0019 Vendor=0001 Product=0001 Version=0100   

N: Name="mtk-tpd-kpd"                               

P: Phys=                                            

S: Sysfs=/devices/virtual/input/input8              

U: Uniq=                                            

H: Handlers=gpufreq_ib event8                       

B: PROP=0                                           

B: EV=3                                             

B: KEY=100040000800 0 0                             

通過這些資訊可以大概知道,哪個輸入裝置對應哪個節點,然後再用下面的指令來檢視具體的輸入事件的内容。

2、檢視輸入事件的内容。

adb shell getevent -t /dev/input/event2

[    5315.440691] 0001 0074 00000001

[    5315.440691] 0000 0000 00000000

[    5316.270721] 0001 0074 00000000

[    5316.270721] 0000 0000 00000000

[    5415.035780] 0001 0073 00000001

[    5415.035780] 0000 0000 00000000

[    5415.298666] 0001 0073 00000000

[    5415.298666] 0000 0000 00000000

[    5417.784254] 0001 0072 00000001

[    5417.784254] 0000 0000 00000000

[    5417.899389] 0001 0072 00000000

[    5417.899389] 0000 0000 00000000

上面是電源鍵、音量上鍵和音量下鍵按下并擡起時由核心生成的原始事件資訊。可以看出按鍵的輸入事件類型編碼為0001,電源鍵的掃描碼為0074、音量上鍵0073、音量下鍵0072,值00000001表示按下、00000000表示擡起。但這些值會随着裝置類型及廠商的不同而有所差別。

當然,也可以通過sendevent往裝置節點中寫入輸入事件,但嘗試數次都沒有成功,具體原因不明,如有知道者,還請分享。

adb shell sendevent /dev/input/event2 1 116 1

adb shell sendevent /dev/input/event2 1 116 0