Program using miltiple if statements to check which keyboard key is pressed


Program using miltiple if statements to check which keyboard key is pressed from the following keys :

Left arrow key,right arrow key or F1 key


Program :

#include
#include

#define LEFT_ARROW 75
#define RIGHT_ARROW 77
#define F1 59

void main()
{
char ch;
clrscr();

do
{
ch = getch();

if(ch == 0)
{
ch = getch();

if(ch == LEFT_ARROW)
{
printf("\nLeft Arrow Key is Pressed");
}

else if(ch == RIGHT_ARROW)
{
printf("\nRight Arrow Key is Pressed");
}

else if(ch == F1)
{
printf("\nF1 Key is Pressed");
}
}

else
{
printf("%c",ch);
}
}while(ch != 27); // Press ESC Key To Close


getch();
}

Output :

0 comments:

Post a Comment