我在通过 uinput 设备事件文件模拟鼠标事件时发现了一个问题。
我可以用 'struct input_event' 结构格式为键盘/鼠标事件编写事件,但只有键事件工作正常,鼠标事件不工作
我启用了 uinput 所需的所有位
UI_SET_EVBIT - EV_KEY (keyboard/mouse), EV_REP (Repeating events), EV_SYN (Sync report events), EV_REL (Mouse)
UI_SET_RELBIT - REL_X, REL_Y (Mouse)
UI_SET_KEYBIT - All the keys in keyboard, BTN_MOUSE, BTN_LEFT, BTN_RIGHT, BTN_MIDDLE
我用下面的代码触发了事件
gettimeofday(&ev.time,0);
ev.type = EV_KEY;
ev.code = BTN_LEFT;
ev.value = <MOUSE PRESS/RELEASE>; // tbhis wil lbe either 0 or 1
if(write(uinputfd, &ev, sizeof(ev)) < 0)
{
return false;
}
// Then send the X
gettimeofday(&ev.time,0);
ev.type = EV_REL;
ev.code = REL_X;
ev.value = x;
if(write(uinputfd, &ev, sizeof(ev)) < 0)
{
return false;
}
// Then send the Y
gettimeofday(&ev.time,0);
ev.type = EV_REL;
ev.code = REL_Y;
ev.value = y;
if(write(uinputfd, &ev, sizeof(ev)) < 0)
{
return false;
}
// Finally send the SYN
gettimeofday(&ev.time,0);
ev.type = EV_SYN;
ev.code = SYN_REPORT;
ev.value = 0;
if(write(uinputfd, &ev, sizeof(ev)) < 0)
{
return false;
}
此外,我可以从相应的 uinput 设备输入文件中读取/打印键盘/鼠标事件。
有谁知道为什么只有鼠标事件不起作用?