56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <linux/uinput.h>
|
|
|
|
|
|
void send_mouse_event(int fd, int type, int code, int value) {
|
|
struct input_event ev;
|
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
ev.type = type;
|
|
ev.code = code;
|
|
ev.value = value;
|
|
|
|
write(fd, &ev, sizeof(ev));
|
|
}
|
|
|
|
int create_virtual_mouse() {
|
|
int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
|
if (fd < 0) {
|
|
perror("uinput");
|
|
exit(1);
|
|
}
|
|
ioctl(fd, UI_SET_EVBIT, EV_REL);
|
|
ioctl(fd, UI_SET_RELBIT, REL_X);
|
|
ioctl(fd, UI_SET_RELBIT, REL_Y);
|
|
ioctl(fd, UI_SET_RELBIT, REL_WHEEL);
|
|
ioctl(fd, UI_SET_RELBIT, REL_HWHEEL);
|
|
ioctl(fd, UI_SET_EVBIT, EV_KEY);
|
|
ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);
|
|
ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT);
|
|
ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE);
|
|
ioctl(fd, UI_SET_EVBIT, EV_REL);
|
|
|
|
struct uinput_setup setup;
|
|
|
|
memset(&setup, 0, sizeof(setup));
|
|
|
|
setup.id.bustype = BUS_USB;
|
|
setup.id.vendor = 0x1234;
|
|
setup.id.product = 0x5678;
|
|
|
|
strcpy(setup.name, "Virtual Keyboard Mouse");
|
|
|
|
ioctl(fd, UI_DEV_SETUP, &setup);
|
|
ioctl(fd, UI_DEV_CREATE);
|
|
|
|
|
|
printf("Virtual mouse created\n");
|
|
|
|
return fd;
|
|
}
|