Monday 25 March 2013

C Program to Check the Arrow Key Pressed

#include<stdio.h>
#include<conio.h>

void main()
{
     char c;
     clrscr();
     fflush(stdin);//To clear the keyboard buffer of all characters
     c=getch();
     printf("%d",c);
     if(c==0)
     {
            c=getch();
            if(c==0x48u)
                   printf("Up Arrow = %02X",c);
            else if(c==0x50u)
                   printf("Down Arrow = %x",c);
            else if(c==0x4bu)
                   printf("Left Arrow = %x",c);
            else if(c==0x4du)
                   printf("Right Arrow = %x",c);
    }
  }