Path: utzoo!mnetor!uunet!husc6!purdue!gatech!galbp!phil From: phil@galbp.LBP.HARRIS.COM (Phil McDonald) Newsgroups: comp.lang.c Subject: Re: keypressed() Message-ID: <3961@galbp.LBP.HARRIS.COM> Date: 22 Feb 88 17:02:25 GMT References: <136@forty2.UUCP> Reply-To: phil@galbp.UUCP (Phil McDonald) Organization: Harris/Lanier, Atlanta, GA Lines: 25 In article <136@forty2.UUCP> eschle@forty2.UUCP (Patrik Eschle) writes: >How do I write a function keypressed(), that returns 0 if no >char is in the input queue and returns the character otherwise? >Keypressed() should not block, and should leave the terminal in its >initial state after returning. > >I can't use curses and have played around with ioctl, but its >really slow. > >Any suggestions? Patrik =========================================================================== I would suggest using the rdchk(s) command. Keypressed() { char c; if (rdchk(stdin) > 0) { read(stdin, &c, sizeof(char)); return(c); } else return(0); }