1 /* This routine illustrates the keypad interface.  To implement
2  * detection of a single escape character, allow for timeout.
3  */
4 
5 #include <stdio.h>
6 #include <slang.h>
7 
8 #include "demolib.c"
9 
10 #define TIMEOUT 2		       /* 2/10 of a second */
11 
getch(void)12 static int getch (void)
13 {
14    int ch;
15 
16    while (0 == SLang_input_pending (1000))
17      continue;
18 
19    ch = SLang_getkey ();
20 
21    if (ch == 033)		       /* escape */
22      {
23 	if (0 == SLang_input_pending (TIMEOUT))
24 	  return 033;
25      }
26 
27    SLang_ungetkey (ch);
28 
29    return SLkp_getkey ();
30 }
31 
main(int argc,char ** argv)32 int main (int argc, char **argv)
33 {
34    int ch;
35 
36    (void) argc; (void) argv;
37 
38    if (-1 == demolib_init_terminal (1, 0))
39      return 1;
40 
41    fprintf (stderr, "This program illustrates the slkeypad facility.\n");
42    fprintf (stderr, "Press any key ('q' quits).\n");
43    while ('q' != (ch = getch ()))
44      {
45 	fprintf (stderr, "Keysym: %d\r\n", ch);
46      }
47 
48    demolib_exit (0);
49 
50    return 0;
51 }
52