title: Detect if mouse button is down
body: <p>I am new to c++ and I am trying to activate a line of code <strong>only</strong> when the left mouse button is held down. In this example, my code works but it seems that it just toggles it. When I click, it spams the <kbd>H</kbd> key then, when I click again, it stops.</p>
  
  <p>Currently I have this code:</p>
  
  <pre><code>if ((GetKeyState(VK_LBUTTON)))
  {
      keybd_event(VkKeyScan('H'),0,0,0);
      Sleep ( 30 );
  }
  </code></pre>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I have inside the function: </p>
  
  <pre><code>int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd );
  </code></pre>