aboutsummaryrefslogtreecommitdiff
path: root/demo.c
blob: feac80cc3f777facbc254df72eee39c06aab3938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>

#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) {
    if(key.type == TERMKEY_TYPE_UNICODE && !key.modifiers)
      printf("%s\n", key.utf8);
    else {
      termkey_snprint_key(tk, buffer, sizeof buffer, &key, 0);
      printf("<%s> or ", buffer);
      termkey_snprint_key(tk, buffer, sizeof buffer, &key, ~0);
      printf("<%s>\n", buffer);
    }

    if(key.type == TERMKEY_TYPE_UNICODE && 
       key.modifiers & TERMKEY_KEYMOD_CTRL &&
       (key.code.codepoint == 'C' || key.code.codepoint == 'c'))
      break;
  }

  termkey_destroy(tk);
}