1

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?

Santhosh
  • 637
  • 1
  • 7
  • 19

1 Answers1

1

I do not have an answer why, but I have noticed that I had to separate keys, absolute, and relative into separate devices. I was hoping somebody else had the answer of how to combine them into one device.

Edit1: Key and relative events are able to be on the same device. If you would still like help for this, I would suggest posting the code used to set up the struct uinput_user_dev, and writing the SET_EVBIT and SET_RELBIT. The sending of events looks fine, so it is probably the initialization, or closing.

Funmungus
  • 134
  • 1
  • 4
  • Although I just thought, maybe calls to UI_SET_KEYBIT have to be after UI_SET_EVBIT for UI_SET_KEYBIT, and UI_SET_RELBIT after UI_SET_EVBIT for relative, and so on. I will test this theory after reorganizing in my project. – Funmungus Sep 26 '15 at 20:38