触控注入
接口介绍
int InjectTouchData(const InputTouch &inputTouch);
功能描述
触控数据注入。
输入参数
|
参数名称 |
说明 |
|---|---|
|
inputTouch |
触控注入参数结构体,详见表2。 |
|
参数名称 |
参数类型 |
说明 |
|---|---|---|
|
pointerID |
number |
真机触点编号,多指触控下会有多个触点,取值范围[0,9],即最多支持10个触点。 |
|
orientation |
number |
真机屏幕旋转角度,默认为0,可设置为1(90°),2(180°), 3(270°)。 |
|
action |
number |
真机触控行为,如ACTION_DOWN, ACTION_UP,取值范围请参考:https://developer.android.com/reference/android/view/MotionEvent |
|
pressure |
number |
真机触控压力值,默认为129。 |
|
physicalWidth |
number |
真机屏幕分辨率宽,默认为0,取值范围[0,2160]。 |
|
physicalHeight |
number |
真机屏幕分辨率高,默认为0,取值范围[0,4096]。 |
|
touchX |
number |
真机触点坐标,取值范围[0,physicalWidth]。 |
|
touchY |
number |
真机触点坐标,取值范围[0,physicalHeight]。 |
|
touchTime |
number |
真机触控时间与上一次ACTION_DOWN时间的偏移量。 |
输出参数
无
返回值
0:成功
小于0:数据注入失败
错误码
请参见错误码。
调用示例
// 触控数据结构体
struct InputTouch {
uint8_t pointerID;
uint8_t orientation;
uint8_t action;
uint16_t pressure;
uint16_t touchX;
uint16_t touchY;
uint16_t physicalWidth;
uint16_t physicalHeight;
int32_t touchTime;
uint8_t reserved[16]; // 保留字段
};
InputTouch inputTouch;
inputTouch.pointerID = 0;
inputTouch.orientation = 0;
inputTouch.action = 0; // ACTION_DOWN
inputTouch.pressure = 129;
inputTouch.physicalWidth = 720;
inputTouch.physicalHeight = 1280;
inputTouch.touchX = 52;
inputTouch.touchY = 157;
inputTouch.touchTime = 0;
int ret = InjectTouchData(inputTouch);
//注意
要确保数据类型是本地字节序,数据来自网络则需要使用ntohl()方法进行本地字节序转换
