Examine the code below on how to get the extended key codes:
int main(){
int a;
printf("Press escape to quit!\n\n"
while(1)
{
a = getch(); /* Get key press and */
if (a == 0 ) { a = getch() + 0x100; } /* Add 256 if extended */
switch ( a )
{
case 27: /* If escape key */
printf( "Escape key. Exiting...\n" );
return 0;
case 328: /* If Up Arrow key */
printf("Up Arrow key\n"
break;
case 336: /* If Down Arrow key */
printf("Down Arrow key\n"
break;
case 333: /* If Right Arrow key */
printf("Right Arrow key\n"
break;
case 331: /* If Left Arrow key */
printf("Left Arrow key\n"
break;
default:
printf("Key code is --> %d\n", a);
}
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.