Mail Archives: djgpp/1995/06/27/06:15:32
I use this all the time and it works:
char ch;
if (kbhit()!=0) {
/* Key hit, read it with getch() and handle it */
ch=getch();
switch (ch) {
case whatever:
whatever;
break;
.
.
.
case 0:
/* Extended key such as arrow keys */
ch=getch(); /* get extended keycode */
switch (ch) {
case whatever:
whatever;
break;
.
.
.
}
}
These extended codes result from there being more than 256 keys (counting
shifted keys, etc.) and chars only holding up to 256. If an extended key
is hit (arrow key for instance) TWO characters go onto the getch() queue.
The first is a 0 (not '0'=48, an actual null) and the second is an
extended code. You should be able to find a table of these extended codes
somewhere.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." ,------------------------------------------------
-- B. Mandelbrot | Paul Derbyshire (PGD) ao950 AT freenet DOT carleton DOT ca
- Raw text -