Xref: utzoo comp.sys.att:5691 comp.unix.questions:11920 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!noao!arizona!naucse!jdc From: jdc@naucse.UUCP (John Campbell) Newsgroups: comp.sys.att,comp.unix.questions Subject: termio under SysV (kbdhit() and getch()) Keywords: typeahead peek, timeout on reads Message-ID: <1174@naucse.UUCP> Date: 28 Feb 89 16:58:53 GMT Distribution: usa Organization: Northern Arizona University, Flagstaff, AZ Lines: 50 I'm trying to implement some getch(), getche(), and kbdhit() type routines under SysV (on a 3b1 actually). I've done the following kind of thing: snippet for getch(): if (ioctl (fileno(keyboard), TCGETA, &term_s) < 0) Fail; term_s.c_lflag &= ~ICANON; term_s.c_cc[VEOF] = 1; /* One character reads */ term_s.c_cc[VEOL] = 0x7f; /* 12.7 seconds (best?) */ if (ioctl (fileno(keyboard), TCSETA, &term_s) < 0) Fail; term_state = 2; /* getche state */ } i = getc(keyboard); which works well enough, except I would like the time limit (MIN) stored in .c_cc[VEOL] to really be infinite. Question 1: Does 0 or -1 work as a "special" infinite value here? As for kbdhit() (returns 1 if there is anything in the typeahead buffer): if (ioctl (fileno(keyboard), TCGETA, &term_s) < 0) Fail; term_s.c_lflag &= ~ICANON; term_s.c_cc[VEOF] = 1; /* One character reads */ term_s.c_cc[VEOL] = 1; /* .1 second read */ if (ioctl (fileno(keyboard), TCSETA, &term_s) < 0) Fail; term_state = 3; /* getche state */ } /* Well, all I can think to do is read, and push back... */ i = getc(keyboard); ungetc(i,keyboard); if (i > 0) { /* Assume EOF is < 0... */ all I could think of doing was read with a .1 second time limit and see if anything came in (and, of course, push it back if nothing did). Question 2: Can anyone think of a better (more direct way) of finding out if anything is in the typeahead under SysV unix? John Campbell ...!arizona!naucse!jdc CAMPBELL@NAUVAX.bitnet unix? Sure send me a dozen, all different colors. -- John Campbell ...!arizona!naucse!jdc CAMPBELL@NAUVAX.bitnet unix? Sure send me a dozen, all different colors.