Originally Posted by
MTK
This I figured out from those lower un-printable ASCII characters that are displayed with that '^' symbol and a letter.
A lot of the keys are three bytes, they usually start with ^[ ESC, int 27:
Code:
#include <stdio.h>
int main () {
int c[3] = {0};
puts("Hit a key then enter.");
scanf("%c%c%c",&c[0],&c[1],&c[2]);
printf("%d %d %d",c[0],c[1],c[2]);
return 0;
}
That seems to include alt (meta) combinations, eg:
Hit a key then enter.
^[^B /* alt-ctrl-b */
27 2 10[root~/C] ./a.out
Hit a key then enter.
^[b /* alt-b */
27 98 10
Which actually these are just two byte*, since the last one (10) was the newline. But PgUp is 3:
Hit a key then enter.
^[[5~
27 91 53
You should look at the readline() library. That provides things for this and for command-line histories, tab completion, etc.
* so I would guess the meta key is 27 (ESC).