aboutsummaryrefslogtreecommitdiffstats
path: root/nkey.c
blob: de92d666b644e68c95a3fdf83215b5be4b9a6ed5 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <ncurses.h>
#include <stdio.h>

int getch_nodelay(void)
{
	int retval;

	nodelay(stdscr, TRUE);
	retval = getch();
	nodelay(stdscr, FALSE);

	return retval;
}

int main(void)
{
	cbreak();
	initscr();
	noecho();
	nonl();

	keypad(stdscr, TRUE);

	while (1) {
		char number[32];
		int c[5] = {
			getch(),
			getch_nodelay(),
			getch_nodelay(),
			getch_nodelay(),
			getch_nodelay()
		};

		if (c[1] == ERR)
			snprintf(number, 32, "%d ", c[0]);
		else if (c[2] == ERR)
			snprintf(number, 32, "%d-%d ", c[0], c[1]);
		else if (c[3] == ERR)
			snprintf(number, 32, "%d-%d-%d ", c[0], c[1], c[2]);
		else if (c[4] == ERR)
			snprintf(number, 32, "%d-%d-%d-%d ", c[0], c[1], c[2],
					c[3]);
		else if (c[5] == ERR)
			snprintf(number, 32, "%d-%d-%d-%d-%d ", c[0], c[1],
					c[2], c[3], c[4]);

		addstr(number);
	}

	return 0;
}