#include #include #include #include #include #include #include #include static int fd; static void write_event (int type, int code, int value) { struct input_event event; gettimeofday (&event.time, NULL); event.type = type; event.code = code; event.value = value; if (write (fd, &event, sizeof (event)) == -1) perror ("write"); } static void touch_up (void) { write_event (EV_KEY, BTN_TOUCH, 0); } static void touch_down (void) { write_event (EV_KEY, BTN_TOUCH, 1); } static void motion (int x, int y) { write_event (EV_ABS, ABS_X, x); write_event (EV_ABS, ABS_Y, y); } static void syn (void) { write_event (EV_SYN, SYN_REPORT, 0); } int main (int argc, char **argv) { struct uinput_user_dev device; int i; fd = open ("/dev/uinput", O_WRONLY | O_NDELAY); if (fd < 0) { fprintf (stderr, "failed to create uinput device\n"); exit (EXIT_FAILURE); } if (ioctl (fd, UI_SET_EVBIT, EV_KEY) < 0) exit (EXIT_FAILURE); if (ioctl (fd, UI_SET_KEYBIT, BTN_TOUCH) < 0) exit (EXIT_FAILURE); if (ioctl (fd, UI_SET_EVBIT, EV_ABS) < 0) exit (EXIT_FAILURE); if (ioctl (fd, UI_SET_ABSBIT, ABS_X) < 0) exit (EXIT_FAILURE); if (ioctl (fd, UI_SET_ABSBIT, ABS_Y) < 0) exit (EXIT_FAILURE); memset (&device, 0, sizeof (device)); snprintf (device.name, UINPUT_MAX_NAME_SIZE, "FAKE-TOUCH UINPUT"); device.id.bustype = BUS_USB; device.id.vendor = 0x1; device.id.product = 0x1; device.id.version = 1; device.absmin[ABS_X] = 0; device.absmax[ABS_X] = 1365; device.absmin[ABS_Y] = 0; device.absmax[ABS_Y] = 767; if (write (fd, &device, sizeof (device)) < 0) exit (EXIT_FAILURE); if (ioctl (fd, UI_DEV_CREATE) < 0) exit (EXIT_FAILURE); sleep (10); touch_down (); motion (100, 100); syn (); sleep (3); touch_up (); syn (); sleep (1); touch_down (); syn (); sleep (1); touch_up (); syn (); sleep (1); touch_down (); motion (110, 110); syn (); for (i = 0; i < 20; i++) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 1000000000 / 20; nanosleep (&ts, NULL); motion (110 + i, 110 + i); syn (); } touch_up (); syn (); close (fd); return 0; }