Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Re: How to test if a key has been hit w/o waiting for a key ? Keywords: kbhit, stdin, getchar Message-ID: <744@mwtech.UUCP> Date: 2 May 90 10:48:52 GMT References: <1990Apr24.000717.7882@cunixf.cc.columbia.edu> <8281@cognos.UUCP> <1990Apr30.182959.18254@cti-software.nl> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 31 In article <1990Apr30.182959.18254@cti-software.nl> pim@cti-software.nl (Pim Zandbergen) writes: [original q&a deleted] > >There is also way to find out if a key has been pressed in System V, >but it is an *ugly* way. If all keyboard input flows thru a central function of your program, it's rather clean - just read a character with timeout set to 0 seconds and store that character in a static variable. Use some impossible value in the static, if no "look ahead" character is available. It's not extremly hard to extend the look ahead to a buffer and count of the available characters or have an additional function to purge them. BTW: If someone request the above information from me, my first reaction is to ask back: "Why do want to do this"? If the one who asks comes from DOS-world, there's a good probability that it's rather a 'timed out read' what he or she wants, and if you let them you can bet they will write an idle loop until some input is available. A: Ohhh, how *incredibly slow* is this UNIX system compared to good old DOS I used before ... B: Let's see ... hmm ; Ehhm, what does this program called "humpfelgrumpf" that is running on the other virtual screen? A: Oh, not much really, gathers some statistical information, not much work at all, some few tenths of a second every thirty seconds. B: And in the meantime. A: Just looks if a key has been pressed. -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83