Using arrow keys in CLion
I am currently doing an assignment, in which i have decided to implement arrow keys as a way to interact with the program. But when i try to test run the program, instead of changing the value of a variable, the arrow keys only moves the cursor around. However, the return key works fine. And also, i tried this code with other IDE and it works just fine too.
Here is my code:
int userInterface(int m)
{
char ch;
int choice = 1;
for(;;)
{
cout << "Current choice: 1" ;
ch = getch();
if(ch == KEY_RIGHT)
{
if(choice < m)
{
choice++;
if(choice < 10)
cout << "\b" << choice;
else if (choice >= 10)
cout << "\b\b" << choice;
}
}
else if (ch == KEY_LEFT)
{
if(choice > 1)
{
choice--;
if(choice < 9)
cout << "\b" << choice;
else if (choice == 9)
cout << "\b\b " << choice;
else if (choice > 9)
cout << "\b\b" << choice ;
}
}
else if(ch == 13) // return key
{
return choice;
}
}
}
Anyway to work around this?
Please sign in to leave a comment.