Hello!
I'm wondering if there is a piece of code that returns the ascii value of the key that is pressed.
Cin and getc won't catch arrow keys or function keys.
Any help appreciated!
Hello!
I'm wondering if there is a piece of code that returns the ascii value of the key that is pressed.
Cin and getc won't catch arrow keys or function keys.
Any help appreciated!
What OS are you using?
There are a lot of ways and I believe no standard one.
For example, getch() I think it is on curses.h or conio.h or ncurses.h
Don't remember exactly how to use it (I think it returns 0 for arrows or function key and then you have to getch() once again to determine which arrow or function key).
Look here for example
Use int a = getchar(), b = getchar(), c = getchar();. The arrow keys return three values, 27, 91, and 65, for up, 66, for down, 67, for right, or 68 for left. So, to manipulate this, do something like...
I'm sorry if this is false, I'm using a GCC-less Mac. The above is entirely from memory.Code:if ((a == 27) && (b == 91)) { switch (c) { case 65 : cout << "You pressed up." << endl; break; case 66 : cout << "You pressed down." << endl; break; case 67 : cout << "You pressed right." << endl; break; case 68 : cout << "You pressed left." << endl; break; default : break; } }