Virtual Keyboard (Linux/libevdev) - sending events

I’m trying to implement a virtual keyboard.

The program sends a keystroke event in the 5 second cycle. Its working on PC (Ubuntu Linux). The problem is that nothing is displayed on BBB.

`
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/uinput.h>

void emit(int fd, int type, int code, int val)
{
struct input_event ie;
ie.type = type;
ie.code = code;
ie.value = val;

/* timestamp values below are ignored */
ie.time.tv_sec = 0;
ie.time.tv_usec = 0;
int res = write(fd, &ie, sizeof(ie));
printf(“emit write bytes=%d fd=%d code=%d val=%d\n”,res, fd, code, val);
}

int main(void)
{

struct uinput_user_dev uud;
int fd;
fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
printf(“fd=%d\n”,fd);

int i1 = ioctl(fd, UI_SET_EVBIT, EV_KEY);
int i2 = ioctl(fd, UI_SET_EVBIT, EV_SYN);
int i3 = ioctl(fd, UI_SET_KEYBIT, KEY_D);
int i4 = ioctl(fd, UI_SET_KEYBIT, KEY_U);
int i5 = ioctl(fd, UI_SET_KEYBIT, KEY_P);
int i6 = ioctl(fd, UI_SET_KEYBIT, KEY_A);

memset(&uud, 0, sizeof(uud));
snprintf(uud.name, UINPUT_MAX_NAME_SIZE, “uinput-keyboard”);

uud.id.bustype = BUS_HOST;
uud.id.vendor = 0x1;
uud.id.product = 0x2;
uud.id.version = 1;

write(fd, &uud, sizeof(uud));
sleep(2);

int i = ioctl(fd, UI_DEV_CREATE);
printf(“dev create =%d\n”, i);

sleep(2);

for(;:wink:
{

emit(fd, EV_KEY, KEY_D, 1);
emit(fd, EV_SYN, SYN_REPORT, 1);
emit(fd, EV_KEY, KEY_D, 0);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_U, 1);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_U, 0);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_P, 1);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_P, 0);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_A, 1);
emit(fd, EV_SYN, SYN_REPORT, 0);
emit(fd, EV_KEY, KEY_A, 0);
emit(fd, EV_SYN, SYN_REPORT, 0);

sleep(5);

}
ioctl(fd, UI_DEV_DESTROY);

close(fd);
return 0;
}

`

lsinput - ev bit are correct? :

/dev/input/event1
   bustype : BUS_HOST
   vendor  : 0x1
   product : 0x2
   version : 1
   name    : "uinput-keyboard"
   bits ev : (null) (null)