Linux之getevent


這兩個命令的源碼在system/core/toolbox/下,sendevent.cgetevent.c

getevent

使用getevent獲得/dev/input/eventX設備匯報的事件,這個命令還會輸出所有event設備的基本信息,如下:

adddevice 1: /dev/input/event1
  name:    "mxc_ts"
add device 2: /dev/input/event0
 name:     "mxckpd"

表明系統有兩個event設備,分別對應着input設備touchscreenkeyboard



Android可以使用sendevent來模擬觸屏,鍵盤以及其他類型的event事件,

sendevent/dev/input/eventX type code value

/dev/input/eventX對應一個event設備,可以通過getevent獲得可用的event設備

type,code, value的定義可參看kernel/include/linux/input.h



type如下定義

[html] viewplaincopy

  1. /*  

  2.  * Event types  

  3.  */  

  4. #define EV_SYN          0x00  

  5. #define EV_KEY          0x01  

  6. #define EV_REL          0x02  

  7. #define EV_ABS          0x03  

  8. #define EV_MSC          0x04  

  9. #define EV_SW           0x05  

  10. #define EV_LED          0x11  

  11. #define EV_SND          0x12  

  12. #define EV_REP          0x14  

  13. #define EV_FF           0x15  

  14. #define EV_PWR          0x16  

  15. #define EV_FF_STATUS        0x17  

  16. #define EV_MAX          0x1f  

  17. #define EV_CNT          (EV_MAX+1)  


一般來說,常用的是EV_KEY,EV_REL, EV_ABS, EV_SYN

分別對應keyboard,相對坐標,絕對坐標,同步事件



EV_SYN則表示一組完整事件已經完成,需要處理,EV_SYNcode定義事件分發的類型

EV_SYN對應的code如下

[html] viewplaincopy

  1. /*  

  2.  * Synchronization events.  

  3.  */  

  4. #define SYN_REPORT      0  

  5. #define SYN_CONFIG      1  

  6. #define SYN_MT_REPORT       2  


EV_KEY
code比較多,這里就不列出來了,可參照input.h



EV_REL對應的code

[html] viewplaincopy

  1. /*  

  2.  * Relative axes  

  3.  */  

  4. #define REL_X           0x00  

  5. #define REL_Y           0x01  

  6. #define REL_Z           0x02  

  7. #define REL_RX          0x03  

  8. #define REL_RY          0x04  

  9. #define REL_RZ          0x05  

  10. #define REL_HWHEEL      0x06  

  11. #define REL_DIAL        0x07  

  12. #define REL_WHEEL       0x08  

  13. #define REL_MISC        0x09  

  14. #define REL_MAX         0x0f  

  15. #define REL_CNT         (REL_MAX+1)  


EV_ABS
對應的code

[html] viewplaincopy

  1. /*  

  2.  * Absolute axes  

  3.  */  

  4.   

  5. #define ABS_X           0x00  

  6. #define ABS_Y           0x01  

  7. #define ABS_Z           0x02  

  8. #define ABS_RX          0x03  

  9. #define ABS_RY          0x04  

  10. #define ABS_RZ          0x05  

  11. #define ABS_THROTTLE        0x06  

  12. #define ABS_RUDDER      0x07  

  13. #define ABS_WHEEL       0x08  

  14. #define ABS_GAS         0x09  

  15. #define ABS_BRAKE       0x0a  

  16. #define ABS_HAT0X       0x10  

  17. #define ABS_HAT0Y       0x11  

  18. #define ABS_HAT1X       0x12  

  19. #define ABS_HAT1Y       0x13  

  20. #define ABS_HAT2X       0x14  

  21. #define ABS_HAT2Y       0x15  

  22. #define ABS_HAT3X       0x16  

  23. #define ABS_HAT3Y       0x17  

  24. #define ABS_PRESSURE        0x18  

  25. #define ABS_DISTANCE        0x19  

  26. #define ABS_TILT_X      0x1a  

  27. #define ABS_TILT_Y      0x1b  

  28. #define ABS_TOOL_WIDTH      0x1c  

  29. #define ABS_VOLUME      0x20  

  30. #define ABS_MISC        0x28  

  31.   

  32. #define ABS_MT_TOUCH_MAJOR  0x30    /* Major axis of touching ellipse */  

  33. #define ABS_MT_TOUCH_MINOR  0x31    /* Minor axis (omit if circular) */  

  34. #define ABS_MT_WIDTH_MAJOR  0x32    /* Major axis of approaching ellipse */  

  35. #define ABS_MT_WIDTH_MINOR  0x33    /* Minor axis (omit if circular) */  

  36. #define ABS_MT_ORIENTATION  0x34    /* Ellipse orientation */  

  37. #define ABS_MT_POSITION_X   0x35    /* Center X ellipse position */  

  38. #define ABS_MT_POSITION_Y   0x36    /* Center Y ellipse position */  

  39. #define ABS_MT_TOOL_TYPE    0x37    /* Type of touching device */  

  40. #define ABS_MT_BLOB_ID      0x38    /* Group a set of packets as a blob */  

  41. #define ABS_MT_TRACKING_ID  0x39    /* Unique ID of initiated contact */  

  42. #define ABS_MT_PRESSURE     0x3a    /* Pressure on contact area */  

  43.   

  44. #define ABS_MAX         0x3f  

  45. #define ABS_CNT         (ABS_MAX+1)  



inputkeyevent

如果想模擬按鍵,sendevent用起來比較繁瑣,可以用inputkeyevent代替

下面是inputkeyevent幾個比較常用的用法:



inputkeyevent 3    // Home

inputkeyevent 4    // Back

inputkeyevent 19  //Up

inputkeyevent 20  //Down

inputkeyevent 21  //Left

inputkeyevent 22  //Right

inputkeyevent 23  //Select/Ok

inputkeyevent 24  //Volume+

inputkeyevent 25  // Volume-

inputkeyevent 82  // Menu 菜單

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM