Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!uiucdcs!carroll From: carroll@cs.uiuc.edu (Alan M. Carroll) Newsgroups: comp.unix.programmer Subject: Re: How can I detect waiting characters in a curses application ? Keywords: curses typeahead Message-ID: <1990Dec6.234823.2763@ux1.cso.uiuc.edu> Date: 6 Dec 90 23:48:23 GMT References: <677@ntpdvp1.UUCP> Sender: news@ux1.cso.uiuc.edu (News) Reply-To: carroll@cs.uiuc.edu (Alan M. Carroll) Organization: Technophiles Inc. - Engineers with Attitude Lines: 38 In article <677@ntpdvp1.UUCP>, samc@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 #include 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