adb-forward-touch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 18139e39c7e81ac8845462d05c42d883bd31923d
parent 1b3ffba5a251cb2aa370e25f51d0b22faa1995ba
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 15 Aug 2022 22:05:34 +0100

add command-line arg for input device to read from

also an error message if /dev/uinput can't be opened

Diffstat:
Madb-forward-touch.c | 24+++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/adb-forward-touch.c b/adb-forward-touch.c @@ -2,12 +2,10 @@ #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; @@ -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);