Mail Archives: djgpp/1999/04/23/10:40:40
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"
- Raw text -