Date: Wed, 28 Dec 1994 22:13:41 -0500 (EST) From: Peter Dufault <dufault@hda.com> To: jbeukema@HK.Super.NET (John Beukema) Cc: freebsd-hackers@freefall.cdrom.com Subject: Re: how to emulate kdhit()B? Message-ID: <199412290313.WAA20727@hda.com> In-Reply-To: <Pine.SUN.3.91.941228171425.5173B-100000@is1.hk.super.net> from "John Beukema" at Dec 28, 94 05:24:21 pm
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <sgtty.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199412290313.WAA20727>