2008-02-07 01:58:41 +01:00
|
|
|
#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);
|
|
|
|
|
2008-02-07 03:21:14 +01:00
|
|
|
termkey_t *tk = termkey_new(0, 0);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
termkey_result ret;
|
2008-02-07 01:58:41 +01:00
|
|
|
termkey_key key;
|
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) {
|
2008-02-07 01:58:41 +01:00
|
|
|
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-" : "",
|
2008-02-07 03:21:14 +01:00
|
|
|
termkey_describe_sym(tk, key.code),
|
2008-02-07 01:58:41 +01:00
|
|
|
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);
|
|
|
|
}
|