Ben Bacarisse said:
What does "directly get" mean? The right way to get keyboard input is
by reading the characters that come from the terminal emulator (or the
real terminal in the unlikely event you have one connected) via the tty
device or a pseudo tty device. You've previously talked about direct
access to the keyboard in a way that suggests you don't like this model,
but any code that tries to bypass all this is unlikely to play well with
other programs.
I mean, without something having to press Enter to complete a line of text
before any keys are available. That would be a bit awkward with a program
like an editor, or if you wanted your own line-input routine. In Windows, I
used kbhit() and getch() for unsophisticated keyboard entry (doing it
properly via a Console API gets hairy, but it will work).
Can you link to the kbhit and getch code?
I tried this for getch():
http://cboard.cprogramming.com/faq-board/27714-faq-there-getch-conio-equivalent-linux-unix.html
And this for kbhit():
http://geezer.osdevbrasil.net/software/kbhit.c
(I remember solving this for an ASR33, I didn't think I'd be facing the same
problem 35 years later!)
Do you really want an editor that drops keystrokes?
Yes. For normal typing of text, it's unlikely the display will not keep up
with the rate of typing. But imagine that someone holds down the PageDown
key on a long document: the key repeats at 20cps, but the display might only
update at 10 screens per second. When the user releases the key, there might
be dozens of keystrokes pending, but the screen will keep on scrolling down
well past the desired position.
I've seen any amount of software having this sort of annoying problem (even
web browers, although associated then with mouse events and scroll bars).
(PDcurses has some logic that if a key is pressed during a 'refresh'
operation, then all pending screen updates are disabled. But I don't see
how that would work well. Likely nothing will be seen until... when? Usually
the user will keep the key pressed until he/she recognises the desired
page or at least the general location; the update is needed. But the feature
can be turned off...)
To do what you've decided to do but in a more portable way. I suggested
extending the input function so that it can return more keycodes
(provided you accept that not all terminals can generate them all) but a
quick test reveals that it already does this. I.e. in an xterm which
can generate all these combinations, wgetch will return distinct codes
for Home, Shift+Home, Ctrl+Home, Alt+Home, Ctrl+Alt+Home and so on for
others that I did not test.
I don't understand unix/linux well enough so the slightest problem eats up
huge amounts of time: something little doesn't work, then the thing needed
to fix it has its own problems, then you realise you're trying to solve
things which have no apparent connection with what you're trying to do. This
was the case with trying to get Curses working with the alternate Debian
distro I have.So I'd rather not have that dependency on Curses. And I didn't
like it's interface anyway.
(Actually I spent quite some time the other day trying to establish whether
Lxterminal, which I use, is the same thing as Xterm; I'm still not sure!)
BTW by wgetch() you mean the curses function? That's the one I'd been using.