| www.delorie.com/djgpp/mail-archives/browse.cgi | search |
| From: | Michael Stewart <michael DOT stewart AT capgemini DOT co DOT uk> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: kbpeek() in DJGPP - C version only.. |
| Date: | Fri, 23 Apr 1999 15:32:33 +0100 |
| Organization: | Cap Gemini Uk |
| Lines: | 32 |
| Message-ID: | <37208435.637A@capgemini.co.uk> |
| References: | <37207CDC DOT B71F192B AT mdh DOT se> |
| NNTP-Posting-Host: | hgty.capgemini.co.uk |
| Mime-Version: | 1.0 |
| X-Trace: | hagen.cloud9.co.uk 924877782 30581 194.42.240.2 (23 Apr 1999 14:29:42 GMT) |
| X-Complaints-To: | abuse AT usenet DOT co DOT uk |
| NNTP-Posting-Date: | 23 Apr 1999 14:29:42 GMT |
| X-Mailer: | Mozilla 3.01 (Win95; I) |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Dan Levin wrote:
>
> Hello !
>
> I wonder if anybody has got a code snippet for "peeking" into the
> keyboard buffer, written in C (C-style only, no iostream...) ? I've done
> some coding myself - but I'm not satisfied with it. I'd like a function,
> say:
>
> int kbpeek();
>
> that returns the ASCII code of the top charcter in the kb buffer. The
> more ANSI C, the better - but I suppose you'll have to go down to
> __dos_int() calls, at the least...or is assembler the only solution...?
I've not tried it but this may work.
int kbpeek () {
int q = 0;
if (kbhit ()) {
q = getc(stdin);
ungetc(q);
}
return q;
}
Michael Stewart
www.freeserve.co.uk/
mike AT reggin DOT freeserve DOT co DOT uk
"Just because you're paranoid, doesn't mean they're not after you"
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |