From 6895da98e3d2200bcd8d4d477cc2415059e6fd1d Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Wed, 16 Feb 2022 20:24:28 +0800 Subject: [PATCH] system/input: add input tools keyboard support Signed-off-by: yinshengkai --- system/input/Kconfig | 2 +- system/input/input.c | 91 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 12 deletions(-) diff --git a/system/input/Kconfig b/system/input/Kconfig index 4c82d529b..7e1763643 100644 --- a/system/input/Kconfig +++ b/system/input/Kconfig @@ -6,7 +6,7 @@ menuconfig SYSTEM_INPUT tristate "Enable input tool" default n - select INPUT_UINPUT + depends on INPUT_UINPUT ---help--- Enable support for a command line input tool. diff --git a/system/input/input.c b/system/input/input.c index af99e7ace..4178b549f 100644 --- a/system/input/input.c +++ b/system/input/input.c @@ -26,6 +26,7 @@ #include #include +#include #include /**************************************************************************** @@ -56,24 +57,29 @@ struct input_cmd_s * Private Function Prototypes ****************************************************************************/ +static int input_button(int argc, char **argv); +static int input_help(int argc, char **argv); +static int input_keydown(int argc, char **argv); +static int input_keyup(int argc, char **argv); +static int input_sleep(int argc, char **argv); +static void input_utouch_move(int fd, int x, int y, int pendown); static int input_utouch_tap(int argc, char **argv); static int input_utouch_swipe(int argc, char **argv); -static int input_sleep(int argc, char **argv); -static int input_help(int argc, char **argv); -static int input_button(int argc, char **argv); -static void input_utouch_move(int fd, int x, int y, int pendown); + /**************************************************************************** * Private Data ****************************************************************************/ static const struct input_cmd_s g_input_cmd_list[] = { - {"help", input_help }, - {"sleep", input_sleep }, - {"tap", input_utouch_tap }, - {"swipe", input_utouch_swipe}, - {"button", input_button }, - {NULL, NULL } + {"help", input_help }, + {"sleep", input_sleep }, + {"tap", input_utouch_tap }, + {"swipe", input_utouch_swipe}, + {"button", input_button }, + {"keyup", input_keyup }, + {"keydown", input_keydown }, + {NULL, NULL } }; /**************************************************************************** @@ -249,6 +255,62 @@ static int input_button(int argc, char **argv) return 0; } +/**************************************************************************** + * Name: input_keyup + ****************************************************************************/ + +static int input_keyup(int argc, char **argv) +{ + int fd; + struct keyboard_event_s key; + + if (argc != 2 || argv[1] == NULL) + { + return -EINVAL; + } + + fd = open("/dev/ukeyboard", O_WRONLY); + if (fd < 0) + { + return -errno; + } + + key.code = strtoul(argv[1], NULL, 0); + key.type = KEYBOARD_RELEASE; + + write(fd, &key, sizeof(struct keyboard_event_s)); + close(fd); + return 0; +} + +/**************************************************************************** + * Name: input_keydown + ****************************************************************************/ + +static int input_keydown(int argc, char **argv) +{ + int fd; + struct keyboard_event_s key; + + if (argc != 2 || argv[1] == NULL) + { + return -EINVAL; + } + + fd = open("/dev/ukbd", O_WRONLY); + if (fd < 0) + { + return -errno; + } + + key.code = strtoul(argv[1], NULL, 0); + key.type = KEYBOARD_PRESS; + + write(fd, &key, sizeof(struct keyboard_event_s)); + close(fd); + return 0; +} + /**************************************************************************** * Name: intput_help ****************************************************************************/ @@ -262,10 +324,17 @@ static int input_help(int argc, char **argv) "\ttap [interval(ms)]\n" "\tswipe [duration(ms)] [distance(pix)]\n" "\tbutton \n" + "\tkeyup: , input keyup 0x61\n" + "\tkeydown: , input keydown 0x61\n" "\tinterval: Time interval between two reports of sample\n" "\tduration: Duration of sliding\n" "\tdistance: Report the pixel distance of the sample twice\n" - "\tbuttonvalue: button value in hex format\n"); + "\tinterval: Time interval between two reports of sample\n" + "\tduration: Duration of sliding\n" + "\tdistance: Report the pixel distance of the sample twice\n" + "\tbuttonvalue: button value in hex format\n" + "\tkeycode: x11 key code, hexadecimal format\n" + ); return 0; }