Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!oliveb!sun!kalli!kevin From: kevin%kalli@Sun.COM (Kevin Sheehan (Consulting Poster Child)) Newsgroups: comp.unix.wizards Subject: Re: How can I read keyboard without stopping Keywords: curses keyboard Message-ID: <63484@sun.uucp> Date: 9 Aug 88 16:54:30 GMT References: <813@ms3.UUCP> Sender: news@sun.uucp Reply-To: kevin@sun.UUCP (Kevin Sheehan (Consulting Poster Child)) Organization: Sun Microsystems, Mountain View Lines: 35 In article <813@ms3.UUCP> isns02@ms3.UUCP (Harris Reavin) writes: > > I would like to know if it is possible to get input data from the >keyboard while my program is constantly looping and displaying output to >the screen. The input comes from a call to "popen()". >I am using C, curses, and BSD4.2 on a VAX-780. I have only been >able to enter input if the display stops for "getch()". This is not acceptable >because I want the display to be continuous unless I am going to change one >of the parameters. For my PC I have Aspen Curses which has a "nodelay()" >function that indicates the presence of characters in the keyboard buffer. >Is there an some way to do this under UNIX? ioctl(fd,FIONREAD, &count) will tell you the number of characters available on a file descriptor. A simple version of what I think you want: /* * returns -1 if no char, -2 for read error, otherwise char */ maygetchar(fd) int fd; { int count; char c; ioctl(fd, FIONREAD, &count); if (!count) { return(-1); } else { if(read(fd, &c, 1) != 1) return(-2); return(c); } } l & h, kev