87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
#include <linux/uinput.h>
|
|
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <stdbool.h>
|
|
|
|
void set_axis(int fd, unsigned short code, int max)
|
|
{
|
|
struct uinput_abs_setup abs_setup;
|
|
memset(&abs_setup, 0, sizeof abs_setup);
|
|
abs_setup.code = code;
|
|
abs_setup.absinfo.maximum = max;
|
|
ioctl(fd, UI_SET_ABSBIT, code);
|
|
ioctl(fd, UI_ABS_SETUP, &abs_setup);
|
|
}
|
|
|
|
static char adb_prefix[] = "adb exec-out getevent ";
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct uinput_setup usetup;
|
|
int i = 50;
|
|
|
|
if(argc < 2) {
|
|
system("adb shell getevent -p");
|
|
fprintf(stderr, "\nUsage: %s /dev/input/eventX\n\n where /dev/input/eventX matches the touchscreen device of your phone\n" , argv[0]);
|
|
exit(1);
|
|
}
|
|
char * adb_command = malloc(strlen(argv[1]) + strlen(adb_prefix));
|
|
strcpy(adb_command, adb_prefix);
|
|
strcat(adb_command, argv[1]);
|
|
|
|
FILE *from_android = popen(adb_command, "r");
|
|
|
|
int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
|
if(fd < 0) {
|
|
perror("Can't open /dev/uinput");
|
|
exit(1);
|
|
}
|
|
|
|
|
|
ioctl(fd, UI_SET_EVBIT, EV_KEY);
|
|
ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);
|
|
|
|
ioctl(fd, UI_SET_EVBIT, EV_ABS);
|
|
|
|
set_axis(fd, ABS_X, 1079);
|
|
set_axis(fd, ABS_Y, 1919);
|
|
set_axis(fd, ABS_PRESSURE, 255);
|
|
set_axis(fd, ABS_MT_SLOT, 9);
|
|
set_axis(fd, ABS_MT_TOUCH_MAJOR, 15);
|
|
set_axis(fd, ABS_MT_TOUCH_MINOR, 15);
|
|
set_axis(fd, ABS_MT_ORIENTATION, 1);
|
|
set_axis(fd, ABS_MT_POSITION_X, 1079);
|
|
set_axis(fd, ABS_MT_POSITION_Y, 1919);
|
|
set_axis(fd, ABS_MT_TRACKING_ID, 65535);
|
|
set_axis(fd, ABS_MT_TOOL_TYPE, 15);
|
|
set_axis(fd, ABS_MT_PRESSURE, 255);
|
|
|
|
ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
|
|
|
|
memset(&usetup, 0, sizeof(usetup));
|
|
usetup.id.bustype = BUS_USB;
|
|
usetup.id.vendor = 0x06cb;
|
|
usetup.id.product = 0x0af9;
|
|
strcpy(usetup.name, "Synaptics s3203b");
|
|
ioctl(fd, UI_DEV_SETUP, &usetup);
|
|
|
|
ioctl(fd, UI_DEV_CREATE);
|
|
|
|
while (true) {
|
|
struct input_event ie;
|
|
if(fscanf(from_android, "%hx %hx %x",
|
|
&ie.type, &ie.code, &ie.value) == EOF)
|
|
break;
|
|
if(write(fd, &ie, sizeof(ie)) < 0)
|
|
break;
|
|
}
|
|
|
|
ioctl(fd, UI_DEV_DESTROY);
|
|
close(fd);
|
|
|
|
return 0;
|
|
}
|