title: Why doesn't my DirectX program recognize that I've released the escape key? (C++)
body: <p>EDIT: After even more code modification, the error is still there, modified code shown:</p>
  
  <p><code>KeyDown()</code>:</p>
  
  <pre><code>const int input_bit_num = 0x8000;
  char keys[256];
  bool KeyDown(int key)
  {
      return (keys[key] &amp; input_bit_num) != 0;
  }
  </code></pre>
  
  <p><code>PollKeyboard()</code>:</p>
  
  <pre><code>LPDIRECTINPUTDEVICE8 di_keyboard;
  void PollKeyboard()
  {
      long result = di_keyboard-&gt;GetDeviceState(sizeof(keys), (LPVOID)&amp;keys);
      char para[16];
      itoa(result, para, 17);
          if(result != DI_OK) MessageBox(NULL, para, "ERROR", MB_OK);
  
  }
  </code></pre>
  
  <p>When I try to put MessageBox within a <code>KeyDown()</code> if statement (as seen below in the game loop), the MessageBox simply coninues to appear even if I stop pressing the key, ie: I press , the "Would you like to quit?" message box appears, I say no, It disappears and then instantly reappears, as if I were still holding the  key.</p>
  
  <p>This is my loop:</p>
  
  <pre><code>void GameRun(HWND hWnd) //called once every frame
  {
      PollKeyboard();
      if(GetTickCount - start &gt;= 30)
      {
          if(KeyDown(DIK_LEFT))
              MoveLeft();
          if(KeyDown(DIK_RIGHT))
              MoveRight();
      }
  
      if(d3ddev-&gt;BeginScene())
      {
          //rendering
      }
  
      if(KeyDown(DIK_ESCAPE))
      {
          //any MessageBox()
          int result = MessageBox(hWnd, "I'm causing so much trouble!", "IMMORTAL", MB_YESNOCANCEL);
          if(result == IDYES)
              //end
      }
  }
  </code></pre>
  
  <p>EDIT: The catch in <code>PollKeyboard()</code> displays the sequence <code>53gd6bcc</code>, I could not, however, find the error code it corresponds to.</p>
  
  <p>EDIT: After another test, I saw that even if the MessageBox is not within a KeyDown() if statement, the glitch still occurs.</p>
  
  <p>EDIT: After a bit more testing, it appears that MessageBox itself is causing the glitch.</p>