From 25441348c4a28fd0821fe7a173e3c6cc166deb16 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 30 Mar 2016 13:20:29 +0200 Subject: kbd support code --- kbdtest.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 kbdtest.c (limited to 'kbdtest.c') diff --git a/kbdtest.c b/kbdtest.c new file mode 100644 index 0000000..849e5e2 --- /dev/null +++ b/kbdtest.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kbd.h" + +/* ---------------------------------------------------------------------- */ + +static const char *keyname[KEY_CNT] = { +#include "KEY.h" +}; + +int main(int argc, char *argv[]) +{ + struct timeval limit; + uint32_t code, mod; + char key[32]; + fd_set set; + int rc,i; + + tty_raw(); + + for (;;) { + FD_ZERO(&set); + FD_SET(0, &set); + limit.tv_sec = 10; + limit.tv_usec = 0; + rc = select(1, &set, NULL, NULL, &limit); + if (0 == rc || !FD_ISSET(0,&set)) + break; + + memset(key, 0, sizeof(key)); + rc = read(0, key, sizeof(key)-1); + if (rc < 1) { + /* EOF */ + break; + } + + code = kbd_parse(key, &mod); + fprintf(stderr, "key: \""); + for (i = 0; key[i] != 0; i++) { + fprintf(stderr, "%c", isprint(key[i]) ? key[i] : '.'); + } + fprintf(stderr, "\" -> %s", keyname[code]); + if (mod & KEY_MOD_SHIFT) + fprintf(stderr, " +shift"); + if (mod & KEY_MOD_CTRL) + fprintf(stderr, " +ctrl"); + fprintf(stderr, "\n"); + } + tty_restore(); + return 0; +} -- cgit