B
BartC
I suspect that you are talking about your won private software, so it's
no matter to me, but I don't want either the problem you describe or
the solution you propose.
No, this is a widespread problem; I've mentioned that I see it frequently
(when a display can't keep up with keyboard entry). There's even a
RosettaCode page devoted to this task**! I'm surprised you haven't come
across it. (And if you have or do, I'd be interested in what solution you
use.)
(** 'Flush the keyboard buffer'. Some languages make it very easy. The C
entry makes use of tcflush(), which I'll look at, maybe.. Interestingly it
does the same manipulations of attributes for it's get-char function as in
my link.)
I would have thought the first line of manual page would have cleared
that up, but maybe you mean Xterm in some other sense.
man lxterminal? It just says it's a terminal emulator. A 'lightweight' one.
And if you use the keypad function, it will read and return key codes.
The ncurses way to do kbhit() is to turn off blocking reads (the nodelay
function) but it's not exactly the same because it works by trying to
get a character rather than telling of there is one to get.
I've done all that (eg. my code to flush the keyboard is below). But there
were some small issues with ncurses (the proliferation of versions, the need
to install it (at least, for the headers), which ran into apt-get problems,
various things that didn't work (such as its keyboard flush routine, hence
the need use the one below), different key codes between pdcurses and
ncurses...). I just thought it simpler if I could do most of what I wanted
via stdin and stdout. But I haven't ruled it out completely because the
alternative doesn't work yet!
void $con_kbdflush(void){
nodelay(stdscr,1);
while (wgetch(stdscr)!=ERR) {
}
nodelay(stdscr,0);
}