minitouch可以实现touch事件的模拟,其touch注入原理和setevent命令类似,都是写input节点来插入input数据。交互方面,通过socket来和调用者通信,接受touch指令。
https://github.com/openstf/minitouchhttps://github.com/openstf/minitouch
minitouch/minitouch.c at master · openstf/minitouch · GitHub
处理代码片段
static int type_b_touch_move(internal_state_t* state, int contact, int x, int y, int pressure)
{
if (contact >= state->max_contacts || !state->contacts[contact].enabled)
{
return 0;
}
WRITE_EVENT(state, EV_ABS, ABS_MT_SLOT, contact);
if (state->has_touch_major)
WRITE_EVENT(state, EV_ABS, ABS_MT_TOUCH_MAJOR, 0x00000006);
if (state->has_width_major)
WRITE_EVENT(state, EV_ABS, ABS_MT_WIDTH_MAJOR, 0x00000004);
if (state->has_pressure)
WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure);
WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, x);
WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, y);
return 1;
}
minitouch的使用不是太方便,从minitouch的通信方式可以受到启发,我们也可以仿照input命令,来实现一个上层调用接口,input命令没有处理多点事件,这里处理一下就可以了,然后通过injectInputEvent来进行事件的注入。
参考资料:
https://www.csdn.net/tags/NtjaQgysNzQ3NTktYmxvZwO0O0OO0O0O.html