title: How to detect if any keyboard key other than a specific keyboard key has been pressed in C++?
body: <p>I have the following code which works fine.</p>
  
  <pre><code>int x = 0;
  int main()
  {    
      while(true) {   
          if (GetKeyState('A') &amp; 0x8000 &amp;&amp; x == 0) {
              Sleep(500);
              x = 1;
          }
          else if (GetKeyState('B') &amp; 0x8000 &amp;&amp; x == 1) {
              Sleep(500);
              x = 2;
          }
          else if (GetKeyState('C') &amp; 0x8000 &amp;&amp; x == 2) {
              Sleep(500);
              x = 0;
              //Do Something
          }
      }
  }
  </code></pre>
  
  <p>In order to execute the <code>//Do Something</code> part of the code, the user must first press <code>A</code>, then <code>B</code> and then <code>C</code> in that order. However the user can press any key in between and it will still work. So in addition to "<code>A</code>+<code>B</code>+<code>C</code>" the following will also work.</p>
  
  <ol>
  <li><code>A</code>+<code>C</code>+<code>B</code>+<code>C</code></li>
  <li><code>A</code>+<code>Q</code>+<code>B</code>+<code>C</code></li>
  <li><code>A</code>+<code>F11</code>+<code>B</code>+<code>8</code>+<code>LSHIFT</code>+<code>Spacebar</code>+<code>Tab</code>+<code>C</code></li>
  </ol>
  
  <p>I want only the <code>A</code>+<code>B</code>+<code>C</code> combination to work. Not any of the above.</p>
  
  <p>The code I am trying to implement is somewhat like this</p>
  
  <pre><code>int x = 0;
  int main()
  {
      while(true) {
  
          if (GetKeyState('A') &amp; 0x8000 &amp;&amp; x == 0) {
              Sleep(500);
              x = 1;
          }
          else if (GetKeyState('B') &amp; 0x8000 &amp;&amp; x == 1) {
              Sleep(500);
              x = 2;
          }
          else if (GetKeyState(/*Any keyboard input other than 'B' or 'A'*/) &amp; 0x8000 &amp;&amp; x == 1) {
              Sleep(500);
              x = 0;
          }
          else if (GetKeyState('C') &amp; 0x8000 &amp;&amp; x == 2) {
              Sleep(500);
              x = 0;
              //Do Something
          }
          else if (GetKeyState(/*Any keyboard input other than 'C' or 'B'*/) &amp; 0x8000 &amp;&amp; x == 2) {
              Sleep(500);
              x = 0;
          }
      }
  }
  </code></pre>
  
  <p>So you see I understand the logic required. I just don't know the correct code required to replace the commented part of my code. Please note that the reason I have entered two keys in the comments is because the user might accidentally press a key twice or thrice for which he/she needs to be excused and code needs to still work.</p>
  
  <p>I think I have tried my best to make this question as understandable as possible. If not feel free to suggest edits.</p>