aboutsummaryrefslogtreecommitdiff
path: root/demo.c
blob: 94b029c4340c461d409c912a5ab653500f83fd73 (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
#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, 1);
      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);
}