home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume32
/
shlm
/
part01
/
getkey.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-20
|
839b
|
43 lines
/*
**
** getkey.c
**
** read a single character from the keyboard and return the ASCII
** value as a return code
**
** to compile, type
**
** cc -O -c getkey.c
** cc -O -c halt.c
** cc -o getkey getkey.o halt.o # add any shared libs here
**
*/
#include <fcntl.h>
#include <termio.h>
int main()
{
int fd, ch;
struct termio savedterm, myterm;
if (ioctl( 0, TCGETA, &savedterm ) == -1)
halt("PERROR getkey: Can not get terminal driver settings.\n");
myterm = savedterm;
myterm.c_lflag &= ~(ICANON|ECHO|ISIG);
myterm.c_cc[VMIN] = 1;
myterm.c_cc[VTIME] = 0;
if (ioctl( 0, TCSETA, &myterm ) == -1)
halt("PERROR getkey: Can not set terminal.\n");
if (read(0, &ch, 1) == -1)
ch = -1;
else write(1, &ch, 1);
if (ioctl( 0, TCSETA, &savedterm ) == -1)
halt("PERROR getkey: Can not set terminal.\n");
return ch;
}