You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/08/15 08:12:26 UTC
[incubator-nuttx-apps] branch master updated: system/input: add input tools keyboard support
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 6895da98e system/input: add input tools keyboard support
6895da98e is described below
commit 6895da98e3d2200bcd8d4d477cc2415059e6fd1d
Author: yinshengkai <yi...@xiaomi.com>
AuthorDate: Wed Feb 16 20:24:28 2022 +0800
system/input: add input tools keyboard support
Signed-off-by: yinshengkai <yi...@xiaomi.com>
---
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 <unistd.h>
#include <nuttx/input/buttons.h>
+#include <nuttx/input/keyboard.h>
#include <nuttx/input/touchscreen.h>
/****************************************************************************
@@ -56,24 +57,29 @@ struct input_cmd_s
* Private Function Prototypes
****************************************************************************/
-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 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);
+
/****************************************************************************
* 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 <x> <y> [interval(ms)]\n"
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)] [distance(pix)]\n"
"\tbutton <buttonvalue>\n"
+ "\tkeyup: <keycode>, input keyup 0x61\n"
+ "\tkeydown: <keycode>, 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"
"\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");
+ "\tbuttonvalue: button value in hex format\n"
+ "\tkeycode: x11 key code, hexadecimal format\n"
+ );
return 0;
}