android自动测试脚本

#!/system/bin/sh
############## device ######################
devicetouch=/dev/input/event1
############### touch ####################
touch()
{
    sleep 2
    sendevent $devicetouch 3 57 1
    sendevent $devicetouch 3 48 1
    sendevent $devicetouch 3 53 $1
    sendevent $devicetouch 3 54 $2
    sendevent $devicetouch 0 0 0
    sendevent $devicetouch 3 48 0
    sendevent $devicetouch 3 57 4294967295
    sendevent $devicetouch 0 0 0
}
############### main #####################
j=1
jmax=20000000
while [ $j -lt $jmax ];
do
    sleep 1
    touch 508 748
    j=$((j+1))
done

 

=====

 

getevent/sendevent源码

这两个命令的源码在system/core/toolbox/下,sendevent.c getevent.c

getevent

使用getevent获得/dev/input/eventX设备汇报的事件,这个命令还会输出所有event设备的基本信息,如下:

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

表明系统有两个event设备,分别对应着input设备touchscreen,keyboard


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如下定义

  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)  
/*
 * Event types
 */
#define EV_SYN          0x00
#define EV_KEY          0x01
#define EV_REL          0x02
#define EV_ABS          0x03
#define EV_MSC          0x04
#define EV_SW           0x05
#define EV_LED          0x11
#define EV_SND          0x12
#define EV_REP          0x14
#define EV_FF           0x15
#define EV_PWR          0x16
#define EV_FF_STATUS        0x17
#define EV_MAX          0x1f
#define EV_CNT          (EV_MAX+1)


一般来说,常用的是EV_KEY, EV_REL, EV_ABS, EV_SYN

分别对应keyboard, 相对坐标, 绝对坐标, 同步事件


EV_SYN则表示一组完整事件已经完成,需要处理,EV_SYN的code定义事件分发的类型

EV_SYN对应的code如下

  1. /*  
  2.  * Synchronization events.  
  3.  */  
  4. #define SYN_REPORT      0  
  5. #define SYN_CONFIG      1  
  6. #define SYN_MT_REPORT       2  
/*
 * Synchronization events.
 */
#define SYN_REPORT      0
#define SYN_CONFIG      1
#define SYN_MT_REPORT       2


EV_KEY的code比较多,这里就不列出来了,可参照input.h


EV_REL对应的code

  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)  
/*
 * Relative axes
 */
#define REL_X           0x00
#define REL_Y           0x01
#define REL_Z           0x02
#define REL_RX          0x03
#define REL_RY          0x04
#define REL_RZ          0x05
#define REL_HWHEEL      0x06
#define REL_DIAL        0x07
#define REL_WHEEL       0x08
#define REL_MISC        0x09
#define REL_MAX         0x0f
#define REL_CNT         (REL_MAX+1)


EV_ABS对应的code

  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)  
/*
 * Absolute axes
 */

#define ABS_X           0x00
#define ABS_Y           0x01
#define ABS_Z           0x02
#define ABS_RX          0x03
#define ABS_RY          0x04
#define ABS_RZ          0x05
#define ABS_THROTTLE        0x06
#define ABS_RUDDER      0x07
#define ABS_WHEEL       0x08
#define ABS_GAS         0x09
#define ABS_BRAKE       0x0a
#define ABS_HAT0X       0x10
#define ABS_HAT0Y       0x11
#define ABS_HAT1X       0x12
#define ABS_HAT1Y       0x13
#define ABS_HAT2X       0x14
#define ABS_HAT2Y       0x15
#define ABS_HAT3X       0x16
#define ABS_HAT3Y       0x17
#define ABS_PRESSURE        0x18
#define ABS_DISTANCE        0x19
#define ABS_TILT_X      0x1a
#define ABS_TILT_Y      0x1b
#define ABS_TOOL_WIDTH      0x1c
#define ABS_VOLUME      0x20
#define ABS_MISC        0x28

#define ABS_MT_TOUCH_MAJOR  0x30    /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR  0x31    /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR  0x32    /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR  0x33    /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION  0x34    /* Ellipse orientation */
#define ABS_MT_POSITION_X   0x35    /* Center X ellipse position */
#define ABS_MT_POSITION_Y   0x36    /* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE    0x37    /* Type of touching device */
#define ABS_MT_BLOB_ID      0x38    /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID  0x39    /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE     0x3a    /* Pressure on contact area */

#define ABS_MAX         0x3f
#define ABS_CNT         (ABS_MAX+1)



input keyevent

如果想模拟按键,send event用起来比较繁琐,可以用input keyevent代替

下面是input keyevent几个比较常用的用法:


input keyevent 3    // Home

input keyevent 4    // Back

input keyevent 19  //Up

input keyevent 20  //Down

input keyevent 21  //Left

input keyevent 22  //Right

input keyevent 23  //Select/Ok

input keyevent 24  //Volume+

input keyevent 25  // Volume-

input keyevent 82  // Menu 菜单


用senevent 模拟触屏事件

sendevent /dev/input/event1 0003 0000 0000015e    // ABS x 坐标

sendevent /dev/input/event1: 0003 0001 000000df    // ABS y 坐标

sendevent /dev/input/event1: 0001 014a 00000001   // BTN touch事件 值为1

sendevent /dev/input/event1: 0003 0018 00000000   // ABS pressure事件

sendevent /dev/input/event1: 0001 014a 00000000   // BTN touch事件 值为0

sendevent /dev/input/event1: 0000 0000 00000000   // sync事件

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值