add command-line arg for input device to read from

also an error message if /dev/uinput can't be opened
main
Daniel Barlow 2022-08-15 22:05:34 +01:00
parent 1b3ffba5a2
commit 18139e39c7
1 changed files with 19 additions and 5 deletions

View File

@ -2,12 +2,10 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
void set_axis(int fd, unsigned short code, int max) void set_axis(int fd, unsigned short code, int max)
{ {
struct uinput_abs_setup abs_setup; 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); 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; struct uinput_setup usetup;
int i = 50; 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); 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_EVBIT, EV_KEY);
ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH); ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);