Normally, I would ask for specific help, but I've been googling the topic of accepting arrow keys for input in a compiler based program for 2 hours, and either a library needed isn't recognized, or C only, or OS specific, or perhaps just beyond my current scope of understanding. So, instead, can anyone just point me to a good, usable source or tutorial on accepting arrow key, or worst case a source on not requiring enter to be pressed.
the only way I know of to read without getting an enter key is to use nonstandard tools. getch and getche are what I use most often for that. There are more complex ways to do this but I don't recommend you go there. You can peek and clear the input buffer with some effort, if you want a true c++ no library solution.
nothing is "c only". You can make all c code work with a c++ program as far as I know. It may be ugly to do this.
as for arrow keys, you need to write a mini program to see what you are getting when one is pressed, probably as a numeric value(s). Once you see what it is sending, you can trap it.
I have been working with ncurses since I posted this. It seemed like the best I was going to find. I forgot all about posting this. I'm about to check out whitenite's now.
#include <iostream>
#include <conio.h>
#include <ctime>
#include <string>
#include <Windows.h>
usingnamespace std;
#define ENTER 13
#define UP 72
#define LEFT 75
#define RIGHT 77
#define DOWN 80
int main()
{
int ch;
ch = _getch();
switch (ch) {
case LEFT: {
cout << "LEFT" << endl;
break;
}
case RIGHT: {
cout << "right" << endl;
break;
}
case UP: {
cout << "up" << endl;
break;
}
case DOWN: {
cout << "down" << endl;
}
break;
case ENTER: {
break;
}
}
return 0;
}
****edit****
The do while loop. I fixed that.
The only issue I'm having now is it works correctly in the little dos window that my antivirus pops up, but it doesn't work in my compiler, which is CLion. Is there any reason that should be doing that?
I don't know anything about the Mac, (If that's what you're using) to be of any help. Sorry. Unless the CLion doesn't like the #include <Windows> , which, of course, you don't really need in that program you have. I needed it for the pause function and the gotoXY function, which, neither you're using.