Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mcnc!rti!ntpdvp1!samc From: samc@ntpdvp1.UUCP (Sam Christie) Newsgroups: comp.unix.programmer Subject: How can I detect waiting characters in a curses application ? Keywords: curses typeahead Message-ID: <677@ntpdvp1.UUCP> Date: 5 Dec 90 23:54:23 GMT Organization: Northern Telecom DMS-10 Div., Raleigh, NC Lines: 48 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. I am using Interactive's 386/IX 2.0.2 on a Dell 386. My application uses curses for a terminal based user interface. Using the application, the user may request that the program perform an operation which takes considerable time. Users, being prone to errors as they are, may wish to abort the operation by pressing the "stop-doing-that,I-didnt-mean-that" key. The code is in a loop and could easily test for such a user request. Something like : while( !done) { /* do a bunch of stuff */ if ( istypeahead( stdscr)) { /* <==== what should this say */ if ( KEY_F(8) == getch( )) break; } } I wrote an istypeahead function as: istypeahead() { int i, j, c; i = fcntl( 0, F_GETFL ); fcntl( 0, F_SETFL, i | O_NDELAY ); c = getchar(); /* didn't use getch() here because */ I don't know how to ungetch() */ fcntl( 0, F_SETFL, i & ( ~O_NDELAY )); if( EOF == c) return( 0); ungetc( c, stdin); return( 1); } This seems to detect typeahead ok, but curses seems to be lost regarding the keys. I suspect it has something to do with curses' internal buffering. (I doubt curses uses getchar() or the buffers associated with fopen() ) Any hints ? -- Sam Christie Standard Disclaimer Applies Northern Telecom - DMS-10 Research Triangle Park, NC EMAIL ...!uunet!mcnc!rti!ntpdvp1!samc 919/992-3917