aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-08-21 20:20:07 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-08-21 20:20:07 +0100
commita06d010504df8b0a77323bf0ffef9ca6bb7ae6b5 (patch)
treedadecf314926ece6f45601b4081b47f0ddd8c695 /demo.c
parent95e87a86d50b0cf1f2c1292ff4cd4ff307ca791f (diff)
downloadtermo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.tar.gz
termo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.tar.xz
termo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.zip
Added termkey_snprint_key() to render nice string outputs of key events
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/demo.c b/demo.c
index 4a5cb38..94b029c 100644
--- a/demo.c
+++ b/demo.c
@@ -3,36 +3,18 @@
#include "termkey.h"
int main(int argc, char *argv[]) {
+ char buffer[50];
termkey_t *tk = termkey_new(0, 0);
termkey_result ret;
termkey_key key;
while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) {
- switch(key.type) {
- case TERMKEY_TYPE_KEYSYM:
- printf("Key %s%s%s%s (code %d)\n",
- key.modifiers & TERMKEY_KEYMOD_SHIFT ? "Shift-" : "",
- key.modifiers & TERMKEY_KEYMOD_ALT ? "Alt-" : "",
- key.modifiers & TERMKEY_KEYMOD_CTRL ? "Ctrl-" : "",
- termkey_get_keyname(tk, key.code.sym),
- key.code.sym);
- break;
- case TERMKEY_TYPE_FUNCTION:
- printf("Function key %s%s%sF%d\n",
- key.modifiers & TERMKEY_KEYMOD_SHIFT ? "Shift-" : "",
- key.modifiers & TERMKEY_KEYMOD_ALT ? "Alt-" : "",
- key.modifiers & TERMKEY_KEYMOD_CTRL ? "Ctrl-" : "",
- key.code.number);
- break;
- case TERMKEY_TYPE_UNICODE:
- printf("Unicode %s%s%s%s (U+%04X)\n",
- key.modifiers & TERMKEY_KEYMOD_SHIFT ? "Shift-" : "",
- key.modifiers & TERMKEY_KEYMOD_ALT ? "Alt-" : "",
- key.modifiers & TERMKEY_KEYMOD_CTRL ? "Ctrl-" : "",
- key.utf8,
- key.code.codepoint);
- break;
+ if(key.type == TERMKEY_TYPE_UNICODE && !key.modifiers)
+ printf("%s\n", key.utf8);
+ else {
+ termkey_snprint_key(tk, buffer, sizeof buffer, &key, 1);
+ printf("<%s>\n", buffer);
}
if(key.type == TERMKEY_TYPE_UNICODE &&