title: C++ Detect when user presses arrow key
body: <p>I have been having a problem with detecting arrow key presses in my C++ console application. I have tried everything I have found, both here and on other tutorial sites, but all of them give me the same thing whenever I press the arrow: </p>
  
  <pre><code>Process returned 0 &lt;0x0&gt; execution time : 2.249 s
  Press any key to continue.
  </code></pre>
  
  <p>Here are all the methods of detecting the key press that I have tried, all ending up the same way. These are the only two left in my code, the others I attempted I deleted instead of commenting out. </p>
  
  <p>Method one:</p>
  
  <pre><code>c1 = getch();
  if(c1 == 0)
  {
  
      c2 = getch();
  
      if(c2 == 72) {cout &lt;&lt; endl &lt;&lt; "Up Arrow" &lt;&lt; endl;}
      else if(c2 == 80) {cout &lt;&lt; endl &lt;&lt; "Down Arrow" &lt;&lt; endl;}
      else{cout &lt;&lt; endl &lt;&lt; "Incorrect Input" &lt;&lt; endl;}
  
  }
  </code></pre>
  
  <p>Method two:</p>
  
  <pre><code>switch(getch()) {
  case 65:
         cout &lt;&lt; endl &lt;&lt; "Up" &lt;&lt; endl;//key up
      break;
  case 66:
      cout &lt;&lt; endl &lt;&lt; "Down" &lt;&lt; endl;   // key down
      break;
  case 67:
      cout &lt;&lt; endl &lt;&lt; "Right" &lt;&lt; endl;  // key right
      break;
  case 68:
      cout &lt;&lt; endl &lt;&lt; "Left" &lt;&lt; endl;  // key left
      break;
  }
  </code></pre>
  
  <p>Is there some error in my code which made me go back to my main method, or did it skip over some code? Is there a faster way to do this? I'm almost 100% sure that my other code doesn't have anything to do with this problem, because I isolated the code from be dependent on any other aspect of the program, and I kept having the same problem. </p>
  
  <p>Again, I tried every method of getting the arrow key press that I could find, and I keep getting the same problem. If it matters, I'm on a Windows 8 Samsung ATIV Smart PC and using the keyboard dock.</p>
  
  <p>Thanks in advance for any help. </p>