Cover V04, I05
Article
Figure 1
Figure 2
Figure 3
Listing 1
Listing 2
Listing 3
Listing 4
Sidebar 1

sep95.tar


Listing 2: Keyboard polling in UNIX

Include and definitions section:
1.  #include <termio.h>
2.  struct termio ttyNParms, ttyOParms;

Coding section to setup
3.  close (0);
4.  if ( open ("/dev/TTY", O_RDWR | O_NDELAY) == -1 )
printf("OPEN ERROR ON USER'S TERMINAL: /dev/tty\n");
5.  if (ioctl(0, TCGETA, &ttyOParms) == -1)
printf("ERROR: Unable to get users tty settings: /dev/tty\n");
6.  ttyNParms = ttyOParms;
7.  ttyNParms.c_lflag     &= ~(ICANON | ECHO);
8.  ttyNParms.c_cc[VMIN]  = 1;
9.  ttyNParms.c_cc[VTIME] = 0;
10.  if (ioctl (0, TCSETA, &ttyNParms) == -1)
printf("ERROR: Unable to get users tty settings: /dev/tty\n");
11. ch = wgetch(stdscr);