Hi I have been trying to create a program which movement is using the arrow keys, however i havenīt been succesful, I donīt know why this is not recognizing the arrow keys, i have even copied and tried to run the example in the FAQ, however, the only key it recognizes is the ESC key, it won't print anithing if I press the arrow keys, i would like to know if someone could help me to correct this because i have used another example program of how to use getch() and it doesnīt recognize the keys, it is supposed to print something for each key I press but for the arrows it will print nothing.
this is the code in the FAQ i have used:
[CODE]enum
{
KEY_ESC = 27,
ARROW_UP = 256 + 72,
ARROW_DOWN = 256 + 80,
ARROW_LEFT = 256 + 75,
ARROW_RIGHT = 256 + 77
};
static int get_code ( void )
{
int ch = getch();
if ( ch == 0 || ch == 224 )
ch = 256 + getch();
return ch;
}
int main ( void )
{
int ch;
while ( ( ch = get_code() ) != KEY_ESC ) {
switch ( ch ) {
case ARROW_UP:
printf ( "UP\n" );
break;
case ARROW_DOWN:
printf ( "DOWN\n" );
break;
case ARROW_LEFT:
printf ( "LEFT\n" );
break;
case ARROW_RIGHT:
printf ( "RIGHT\n" );
break;
}
}
return 0;
}
[/CODE)
And this is the example program of the C help on getch()
I hope spmeone can help me, i have been trying to do this for three days.Code:/* getch example */ #include <conio.h> #include <stdio.h> int main(void) { int c; int extended = 0; c = getch(); if (!c) extended = getch(); if (extended) printf("The character is extended\n"); else printf("The character isn't extended\n"); return 0; }
Thx
My OS is win XP home
My Compiler is borland, I use Turbo C++ version 4.5