blob: ac2a736cf1e3ef768a86a4e12b627a0928fd3d3f (
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
52
|
/* This routine illustrates the keypad interface. To implement
* detection of a single escape character, allow for timeout.
*/
#include <stdio.h>
#include <slang.h>
#include "demolib.c"
#define TIMEOUT 2 /* 2/10 of a second */
static int getch (void)
{
int ch;
while (0 == SLang_input_pending (1000))
continue;
ch = SLang_getkey ();
if (ch == 033) /* escape */
{
if (0 == SLang_input_pending (TIMEOUT))
return 033;
}
SLang_ungetkey (ch);
return SLkp_getkey ();
}
int main (int argc, char **argv)
{
int ch;
(void) argc; (void) argv;
if (-1 == demolib_init_terminal (1, 0))
return 1;
fprintf (stderr, "This program illustrates the slkeypad facility.\n");
fprintf (stderr, "Press any key ('q' quits).\n");
while ('q' != (ch = getch ()))
{
fprintf (stderr, "Keysym: %d\r\n", ch);
}
demolib_exit (0);
return 0;
}
|