aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-07 00:58:41 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-07 00:58:41 +0000
commita503403226e4e2a929efddd4a2d0daad9c33c596 (patch)
tree032aa941ca6153c2e61fd01711e623d487aecfbe /demo.c
downloadtermo-a503403226e4e2a929efddd4a2d0daad9c33c596.tar.gz
termo-a503403226e4e2a929efddd4a2d0daad9c33c596.tar.xz
termo-a503403226e4e2a929efddd4a2d0daad9c33c596.zip
Initial attempt
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/demo.c b/demo.c
new file mode 100644
index 0000000..512a99f
--- /dev/null
+++ b/demo.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "termkey.h"
+
+int main(int argc, char *argv[]) {
+ struct termios termios;
+
+ if(tcgetattr(0, &termios)) {
+ perror("ioctl(TCIOGETS)");
+ exit(1);
+ }
+
+ int old_lflag = termios.c_lflag;
+ termios.c_lflag &= ~(ICANON|ECHO);
+
+ tcsetattr(0, TCSANOW, &termios);
+
+ termkey_t *tk = termkey_new(0, TERMKEY_FLAG_CONVERTKP);
+
+ termkey_key key;
+
+ while(termkey_waitkey(tk, &key) && key.code != TERMKEY_SYM_EOF) {
+ if(key.flags & TERMKEY_KEYFLAG_SPECIAL)
+ printf("Key %s%s%s%s (code %d)\n",
+ key.modifiers & TERMKEY_KEYMOD_SHIFT ? "S-" : "",
+ key.modifiers & TERMKEY_KEYMOD_ALT ? "A-" : "",
+ key.modifiers & TERMKEY_KEYMOD_CTRL ? "C-" : "",
+ termkey_describe_sym(key.code),
+ key.code);
+ else
+ printf("Key %s%s%s%s (U+%04X)\n",
+ key.modifiers & TERMKEY_KEYMOD_SHIFT ? "S-" : "",
+ key.modifiers & TERMKEY_KEYMOD_ALT ? "A-" : "",
+ key.modifiers & TERMKEY_KEYMOD_CTRL ? "C-" : "",
+ key.utf8,
+ key.code);
+
+ if(key.modifiers & TERMKEY_KEYMOD_CTRL && key.code == 'C')
+ break;
+ }
+
+ termios.c_lflag = old_lflag;
+ tcsetattr(0, TCSANOW, &termios);
+}