// uinput.c #include #include #include #include #include #include #include #include #include #include #include /* * Globals */ static int uinp_fd = -1; struct uinput_user_dev uinp; // uInput device structure struct input_event event; // Input device structure /* * Setup the uinput device */ int setup_uinput_device() { // Temporary variable int i = 0; // Open the input device uinp_fd = open("/dev/input/uinput", O_WRONLY | O_NDELAY); if (&uinp_fd == NULL) { printf("Unable to open /dev/input/uinput\n"); return -1; } memset(&uinp, 0, sizeof(uinp)); // Intialize the uInput device to NULL strncpy(uinp.name, "Acer T230H", UINPUT_MAX_NAME_SIZE); uinp.id.version = 4; uinp.id.bustype = BUS_USB; uinp.absmax[ABS_X] = 1920+1440; // i have another monitor connected; uinp.absmin[ABS_X] = 0; uinp.absfuzz[ABS_X] = 3; uinp.absmin[ABS_X] = 0; uinp.absmax[ABS_Y] = 1080; uinp.absmin[ABS_Y] = 0; uinp.absfuzz[ABS_Y] = 3; uinp.absmin[ABS_Y] = 0; // Setup the uinput device ioctl(uinp_fd, UI_SET_EVBIT, EV_KEY); ioctl(uinp_fd, UI_SET_EVBIT, EV_ABS); ioctl(uinp_fd, UI_SET_ABSBIT, ABS_X); ioctl(uinp_fd, UI_SET_ABSBIT, ABS_Y); ioctl(uinp_fd, UI_SET_KEYBIT, BTN_LEFT); /* * Create input device into input sub-system */ write(uinp_fd, &uinp, sizeof(uinp)); if (ioctl(uinp_fd, UI_DEV_CREATE)) { printf("Unable to create UINPUT device.\n"); return -1; } return 1; } void pukk() { int fd; unsigned int x, y, xx, yy; unsigned char buf[30]; fd = open("/dev/hidraw6", O_RDONLY); while (1) { read(fd, buf, sizeof(buf)); x = buf[4] + (unsigned int) buf[5] * 256; y = buf[6] + (unsigned int) buf[7] * 256; xx = buf[10] + (unsigned int) buf[11] * 256; yy = buf[12] + (unsigned int) buf[13] * 256; // set x & y memset(&event, 0, sizeof(event)); gettimeofday(&event.time, NULL); event.type = EV_ABS; event.code = ABS_X; event.value = x + 1440; // a have another monitor connected :) write(uinp_fd, &event, sizeof(event)); event.type = EV_ABS; event.code = ABS_Y; event.value = y; write(uinp_fd, &event, sizeof(event)); event.type = EV_SYN; event.code = SYN_REPORT; event.value = 0; write(uinp_fd, &event, sizeof(event)); if (buf[2] == 7) { // BTN1 pressed memset(&event, 0, sizeof(event)); gettimeofday(&event.time, NULL); event.type = EV_KEY; event.code = BTN_LEFT; event.value = 1; write(uinp_fd, &event, sizeof(event)); event.type = EV_SYN; event.code = SYN_REPORT; event.value = 0; write(uinp_fd, &event, sizeof(event)); } if (buf[2] == 4) { // BTN1 released memset(&event, 0, sizeof(event)); gettimeofday(&event.time, NULL); event.type = EV_KEY; event.code = BTN_LEFT; event.value = 0; write(uinp_fd, &event, sizeof(event)); event.type = EV_SYN; event.code = SYN_REPORT; event.value = 0; write(uinp_fd, &event, sizeof(event)); } printf("\n%ux%u %ux%u [%u]\n", x, y, xx, yy, buf[2]); } close(fd); } int main() { // Return an error if device not found. if (setup_uinput_device() < 0) { printf("Unable to find uinput device\n"); return -1; } pukk(); ioctl(uinp_fd, UI_DEV_DESTROY); close(uinp_fd); return 0; }