Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <linux/input.h>
- #include <linux/uinput.h>
- #include <time.h>
- #define RELEASE 0
- #define PRESS 1
- #define AUTOREPEAT 2
- #define total_time(x) (x.tv_sec * 100000 + x.tv_usec)
- int main(int argc, char *argv[])
- {
- struct uinput_user_dev ui_dev;
- struct input_event ev;
- int fd;
- fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
- if(fd <= 0)
- {
- printf("Unable to open /dev/uinput\n");
- return -1;
- }
- usleep(100);
- memset(&ev, 0, sizeof(ev));
- memset(&ui_dev, 0, sizeof(ui_dev));
- strncpy(ui_dev.name, "uinput-test", UINPUT_MAX_NAME_SIZE);
- ui_dev.id.bustype = BUS_USB;
- ui_dev.id.vendor = 0x1234;
- ui_dev.id.product = 0xABCD;
- ui_dev.id.version = 1;
- ioctl(fd, UI_SET_EVBIT, EV_KEY);
- ioctl(fd, UI_SET_EVBIT, EV_REP);
- ioctl(fd, UI_SET_KEYBIT, KEY_D);
- write(fd, &ui_dev, sizeof(ui_dev));
- ioctl(fd, UI_DEV_CREATE);
- usleep(100);
- while(1)
- {
- gettimeofday(&ev.time, NULL);
- ev.type = EV_KEY;
- ev.code = KEY_D;
- ev.value = PRESS;
- write(fd, &ev, sizeof(ev));
- gettimeofday(&ev.time, NULL);
- ev.type = EV_KEY;
- ev.code = KEY_D;
- ev.value = RELEASE;
- write(fd, &ev, sizeof(ev));
- gettimeofday(&ev.time, NULL);
- ev.type = EV_SYN;
- ev.code = SYN_REPORT;
- ev.value = 0;
- write(fd, &ev, sizeof(ev));
- usleep(500 * 1000);
- }
- ioctl(fd, UI_DEV_DESTROY);
- close(fd);
- printf("\nExit.\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement