From 18139e39c7e81ac8845462d05c42d883bd31923d Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 15 Aug 2022 22:05:34 +0100 Subject: [PATCH] add command-line arg for input device to read from also an error message if /dev/uinput can't be opened --- adb-forward-touch.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/adb-forward-touch.c b/adb-forward-touch.c index 5273f16..0c735e7 100644 --- a/adb-forward-touch.c +++ b/adb-forward-touch.c @@ -2,12 +2,10 @@ #include #include #include +#include #include #include - - - void set_axis(int fd, unsigned short code, int max) { struct uinput_abs_setup abs_setup; @@ -18,14 +16,30 @@ void set_axis(int fd, unsigned short code, int max) ioctl(fd, UI_ABS_SETUP, &abs_setup); } -int main(void) +static char adb_prefix[] = "adb exec-out getevent "; + +int main(int argc, char *argv[]) { struct uinput_setup usetup; int i = 50; - FILE *from_android = popen("adb exec-out getevent /dev/input/event2", "r"); + 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);