So I want a function to return the char representing an arrow key to use it further in the main, and here's my try:
#include <conio.h>
#include <iostream>
using namespace std;
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
char func()
{
char c;
c=_getch();
switch((c=_getch())) {
case KEY_UP:
return c;
case KEY_DOWN:
return c;
case KEY_LEFT:
return c;
case KEY_RIGHT:
return c;
default:
break;
}
return 0;
}
int main()
{
cout<<func();
}
But it doesn't work , it just prints the character with the 'actual' ASCII value (like 'M' if I pressed the right arrow key) , So i want to know how to solve this problem . Also why is it that the same ASCII value is used for a character as well as the arrow key? What does it mean?
Another question is that modern IDE's don't use getch() or _getch() functions , so what is the alternate of that?