I have a simple program that can detect arrow key presses from the user, though I have two questions. But First, here's the code:
#include <iostream>
#include <conio.h>
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 77
#define KEY_RIGHT 75
using namespace std;
int main()
{
while(1)
{
char c = getch();
cout << "Hello";
switch(c) {
case KEY_UP:
cout << endl << "Up" << endl;//key up
break;
case KEY_DOWN:
cout << endl << "Down" << endl; // key down
break;
case KEY_LEFT:
cout << endl << "Right" << endl; // key right
break;
case KEY_RIGHT:
cout << endl << "Left" << endl; // key left
break;
default:
cout << endl << "NULL" << endl; // any other key
break;
}
}
return 0;
}
Question 1: Whenever I press any arrow key, why does it print "Hello" TWICE?
Question 2: Whenever I press any arrow or non-arrow key, it prints the default switch case, "NULL", which is supposed to be only for non-arrow keys. Why is this?
Thanks