Using this short snippet of code I am able to capture events from the keyboard (/dev/input/event1) and print them properly. However, sending them to the Xvfb display using XTestFakeKeyEvent does not work even if XTestFakeKeyEvent returns successful.
char devname[] = "/dev/input/event1";
int device = open(devname, O_RDONLY);
struct input_event ev;
signal(SIGINT, INThandler);
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {fprintf(stderr, "unable to connect to display");return 7;}
while(1)
{
read(device,&ev, sizeof(ev));
printf("Key: %i State: %i\n",ev.code,ev.value);
if(ev.code!=4)
if(!(XTestFakeKeyEvent(dpy, ev.code, ev.value, 0)))
{fprintf(stderr, "unable to send keystroke\n");return 7;};
}
I thought the problem was with the compatibility between Xvfb and XTestFakeKeyEvent but I am able to send keystrokes to the display using the xdotool program in the shell, which uses XTestFakeKeyEvent. It's possible that I'm doing this wrong, I'm not familiar with X11 programming. Thank you in advance.