I was finding a problem in emulating the mouse events via uinput device event files.
I could write the event with 'struct input_event' structure format for keyboard/mouse events but only key events were working fine and mouse events were not working
I enabled all the bits required for 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
I triggered the events with the below code
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;
}
Also, I could read/print the Keyboard/Mouse events from the corresponding uinput device input files.
Does anybody have any idea why only mouse events were not working?