I had a problem with detecting arrow keys in my C ++ console application. I tried everything I found, both here and on other sites, but they all give me the same thing when I click the arrow:
Process returned 0 <0x0> execution time : 2.249 s Press any key to continue.
Here are all the keystroke detection methods I tried, it all ends the same way. These are just the two remaining in my code, the others that I tried to delete, instead of commenting.
First method:
c1 = getch(); if(c1 == 0) { c2 = getch(); if(c2 == 72) {cout << endl << "Up Arrow" << endl;} else if(c2 == 80) {cout << endl << "Down Arrow" << endl;} else{cout << endl << "Incorrect Input" << endl;} }
Method Two:
switch(getch()) { case 65: cout << endl << "Up" << endl;//key up break; case 66: cout << endl << "Down" << endl; // key down break; case 67: cout << endl << "Right" << endl; // key right break; case 68: cout << endl << "Left" << endl; // key left break; }
Is there some kind of error in my code that made me return to my main method or skip some code? Is there a faster way to do this? I am almost 100% sure that my other code has nothing to do with this problem, because I isolated the code from dependency on any other aspect of the program, and I had the same problem.
Again, I tried every way to get the arrow key press that I could find, and I have the same problems. If that matters, I am on a Windows 8 Samsung ATIV Smart PC and using a keyboard dock.
Thanks in advance for any help.
c ++ windows-8 console-application arrow-keys
Splatface development
source share