Try this code, see if it works/helps. I wrote it using Borland 5.5.
Code:#include <iostream> #include <conio.h> #include <ctype.h> using std::cout; using std::endl; int main(void) { int c = 0; cout <<"Press a key, x to exit" <<endl; while (c != 'x') { switch (c = getch()) { case 0: switch (c = getch()) { case 72: /* code for Up key */ cout <<"Up" <<endl; break; case 75: /* code for Left key */ cout <<"Left" <<endl; break; case 77: /* code for Right key */ cout <<"Right" <<endl; break; case 80: /* code for Down key */ cout <<"Down" <<endl; break; default: /* other extended key */ cout <<"That was an extended key, with value "<<c<<endl; } break; case 'x' : cout <<"Thanks for playing" <<endl; break; case '\r': cout <<"That was the enter button" <<endl; break; default : if (isgraph(c)) cout <<"That was a " <<(char)c <<endl; break; } } return(0); } /* Output: Press a key, x to exit Left Up Right Down That was a q That was a w That was a e That was a r That was an extended key, with value 59 That was an extended key, with value 60 That was an extended key, with value 61 That was an extended key, with value 62 That was the enter button That was the enter button Thanks for playing */



LinkBack URL
About LinkBacks


