我设法在我的LG设备上以编程方式(C代码)注入多点触控事件,将它们注入/dev/input/event0
。
但是按键注射没有成功。我能够通过adb shell input keyevent
注入密钥,但我没有看到/dev/input/event*
文件中发生任何事情。看起来他们都没有收到任何东西。有谁知道如何本地化文件注入密钥的位置?
提前谢谢。
更新
init设备代码:
ioctl (obj->m_fd, UI_SET_EVBIT, EV_KEY);
ioctl (obj->m_fd, UI_SET_KEYBIT, BTN_TOUCH);
ioctl (obj->m_fd, UI_SET_KEYBIT, KEY_BACK);
ioctl (obj->m_fd, UI_SET_KEYBIT, KEY_HOMEPAGE);
for (i = KEY_RESERVED; i <= KEY_UNKNOWN; i++)
ioctl(obj->m_fd, UI_SET_KEYBIT, i);
ioctl (obj->m_fd, UI_SET_EVBIT, EV_ABS);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_X);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_Y);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_MT_TOUCH_MAJOR);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
ioctl (obj->m_fd, UI_SET_ABSBIT, ABS_MT_PRESSURE);
注入触摸事件代码(工作)
intSendEvent( obj->m_fd, EV_ABS, ABS_MT_TRACKING_ID, 0 );
intSendEvent( obj->m_fd, EV_ABS, ABS_MT_POSITION_X, obj->x );
intSendEvent( obj->m_fd, EV_ABS, ABS_MT_POSITION_Y, obj->y );
intSendEvent( obj->m_fd, EV_ABS, ABS_MT_TOUCH_MAJOR, obj->sq );
intSendEvent( obj->m_fd, EV_ABS, ABS_MT_PRESSURE, obj->pr );
intSendEvent( obj->m_fd, EV_SYN, SYN_MT_REPORT, 0);
intSendEvent( obj->m_fd, EV_SYN, SYN_REPORT, 0);
intSendEvent( obj->m_fd, EV_SYN, SYN_MT_REPORT, 0);
intSendEvent( obj->m_fd, EV_SYN, SYN_REPORT, 0);
在KEY_RESERVED <= obj->keyCode <=KEY_UNKNOWN
(不工作)
intSendEvent(obj->m_fd, EV_KEY, obj->keyCode, 1);
intSendEvent( obj->m_fd, EV_SYN, SYN_REPORT, 0);
intSendEvent(obj->m_fd, EV_KEY, obj->keyCode, 0);
intSendEvent( obj->m_fd, EV_SYN, SYN_REPORT, 0);
发送事件功能
void intSendEvent(int fd_kb,int type, int code, int value)
{
debug("intSendEvent call (%d,%d,%d,%d)", fd_kb, type, code, value);
struct uinput_event event;
int len;
if (fd_kb <= fileno(stderr))
return;
memset(&event, 0, sizeof(event));
event.type = type;
event.code = code;
event.value = value;
len = write( fd_kb, &event, sizeof(event) );
debug("intSendEvent done:%d",len);
}
答案 0 :(得分:0)
嗯,看起来我正在使用的设备根本没有内置键盘,因此/dev/input
上没有设备文件,因此将文本直接注入设备文件看起来是不可能的。但getevent -lit
命令说我有以下设备:
add device 2: /dev/input/event6
bus: 0000
vendor 0000
product 0000
version 0000
name: "ats_input"
location: ""
id: ""
version: 1.0.1
events:
KEY (0001): KEY_ESC KEY_1 KEY_2 KEY_3
KEY_4 KEY_5 KEY_6 KEY_7
KEY_8 KEY_9 KEY_0 KEY_END
KEY_VOLUMEDOWN KEY_VOLUMEUP KEY_POWER KEY_SEND
KEY_NUMERIC_0 KEY_NUMERIC_1 KEY_NUMERIC_2 KEY_NUMERIC_3
KEY_NUMERIC_4 KEY_NUMERIC_5 KEY_NUMERIC_6 KEY_NUMERIC_7
KEY_NUMERIC_8 KEY_NUMERIC_9 KEY_NUMERIC_STAR KEY_NUMERIC_POUND
ABS (0003): ABS_MT_TOUCH_MAJOR
这对于数字注入来说已经足够了,这对我来说已经足够了。
adb shell input keyevent ...
适用于虚拟键盘,因此不使用任何设备文件(感谢Chris Stratton)