From owner-freebsd-hackers Wed Dec 28 19:12:37 1994 Return-Path: hackers-owner Received: (from root@localhost) by freefall.cdrom.com (8.6.9/8.6.6) id TAA19563 for hackers-outgoing; Wed, 28 Dec 1994 19:12:37 -0800 Received: from hda.com (hda.com [199.232.40.182]) by freefall.cdrom.com (8.6.9/8.6.6) with ESMTP id TAA19549 for ; Wed, 28 Dec 1994 19:12:34 -0800 Received: (dufault@localhost) by hda.com (8.6.9/8.3) id WAA20727; Wed, 28 Dec 1994 22:13:41 -0500 From: Peter Dufault Message-Id: <199412290313.WAA20727@hda.com> Subject: Re: how to emulate kdhit()B? To: jbeukema@HK.Super.NET (John Beukema) Date: Wed, 28 Dec 1994 22:13:41 -0500 (EST) Cc: freebsd-hackers@freefall.cdrom.com In-Reply-To: from "John Beukema" at Dec 28, 94 05:24:21 pm X-Mailer: ELM [version 2.4 PL24] Content-Type: text Content-Length: 1081 Sender: hackers-owner@freebsd.org Precedence: bulk John Beukema writes: > > > I cannot get the function kbhit() which works well under SCO to work under > FBSD. The function which tries to read 1 char from stdin after setting > flags to nonblocking, always returns true ie, keyboard hit when the term > is in 'cooked' mode. Can anyone point me to a way to do this? > jbeukema This is the "kbhit" we use. This "kbhit" just returns whether or not something is pending, which is all the Microsoft library promised when this was written (way back when). It works properly non blocking or blocking, and as someone noted, probably only makes sense when it is set to non-blocking. Maybe you can modify this to do what you need. #include #include int kbhit(void) { int n; if (ioctl(fileno(stdin), FIONREAD, &n) == -1) n = 0; return n != 0; } Peter -- Peter Dufault Real Time Machine Control and Simulation HD Associates, Inc. Voice: 508 433 6936 dufault@hda.com Fax: 508 433 5267 ++++ Formerly hd@world.std.com. E-mail problems? Tell hdslip@iii.net