First, you can detect any keystroke key value
#include <stdio.h>#include<conio.h>int main () { char ch; while ((Ch=getch ())! =0x1B/**/{ printf ("% d \ n"
is the key value of the next key or lower.
Second, the console reads the direction key directive
Method One
//capturing key Values#include <stdio.h>#include<conio.h>intMain () {intch; while((Ch=getch ())! =0x1B)/*Press ESC to quit ...*/ { Switch(CH) { Case 0xE0: Switch(ch=Getch ()) { Case the: printf ("up\n"); Break; Case the: printf ("down\n"); Break; Case the: printf ("left\n"); Break; Case the: printf ("right\n"); Break; default: Break; } Break; default: Break; } }}
Method Two
#include <stdio.h>#include<stdlib.h>#include<conio.h>#include<windows.h>intMain () {Charkey; while(1) { //int t=1;key=Getch (); Switch(key) { Case- +: Key=Getch (); Switch(key) { Case the: printf ("up\n"); Break; Case the: printf ("down\n"); Break; Case the: printf ("left\n"); Break; Case the: printf ("right\n"); Break; Case-123: printf ("f11\n"); Break; Case-122: printf ("f12\n"); Break; default: //printf ("%x,%d,%c\n", t,t,t);printf"NULL"); Break; } Break; default: //printf ("%x,%d,%c\n", t,t,t);printf"NULL"); Break; } } return 0;}
C language console read up and DOWN ARROW key instructions