How can I detect waiting characters in a curses application ?

Alan M. Carroll carroll at cs.uiuc.edu
Fri Dec 7 10:48:23 AEST 1990


In article <677 at ntpdvp1.UUCP>, samc at ntpdvp1.UUCP (Sam Christie) writes:
> Would some kind sole tell me the name of the curses function
> which checks for input without blocking ? If none exists, then please
> read on and help me create one.
> 

Try this. (test by compiling and running. Type and hit return. Works
for me on ISC 2.0.2).

#include <stropts.h>
#include <poll.h>

int istypeahead(fd) int fd;		/* file descriptor */
{
  int n;
  struct pollfd p_fd[1];

  p_fd->fd = fd;
  p_fd->events = POLLIN;

  n = poll(p_fd, 1, 0);
  return n;
}

main()
{
  while (1)
    {
      if (istypeahead(0)) printf("Input waiting\n");
      else printf("No input\n");
      sleep(1);
    }
}

-- 
Alan M. Carroll                "It's psychosomatic. You need a lobotomy.
Epoch Development Team          I'll get a saw."
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll



More information about the Comp.unix.programmer mailing list