title: How to use GetAsyncKeyState to see key was pressed for x seconds
body: <p>I am trying to create a code which will detect if the mouse button has been pressed. So far i have a code which will detect if the button has been pressed once. But it isn't letting me check if the button was continuously pressed. For e.g left mouse button pressed, this will start a timer, after 0.5 seconds it will check again and if it is still down output something. </p>
  
  <p>I want to set it up like this</p>
  
  <pre><code>while (true)
  {
  
      if (GetAsyncKeyState(VK_LBUTTON) &amp; (0x8000 != 0))
      {
  
          cout &lt;&lt; ("left button pressed") &lt;&lt; endl;
          Sleep(500);
          if (GetAsyncKeyState(VK_LBUTTON) &amp; (0x8000 != 0))
          {
  
              cout &lt;&lt; ("Left button held down") &lt;&lt; endl;
          }
  
      }
  }
  </code></pre>
  
  <p>However, it does not work, it only outputs the second statement if i double click in quick succession.</p>
  
  <blockquote>
    <p>Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState. </p>
  </blockquote>
  
  <p>The msdn website says that. Does this mean i should check if it is UP after the time to get the result i want.</p>