title: C++ Registering A Single Mouse Click
body: <p>I have a question about registering a single mouse click on a hotspot - it's been giving me all sorts of problems, and I cannot seem to find the answer here, in any of my books, or on Google. I've only been at programming for a couple months, so bear with me. </p>
  
  <p>I have managed to create an (albeit primitive and not very elegant) hotbox where someone rolls over a button and their icon changes. If they click on the button, it populates a vector on another screen and plays a sound. That's all fine. However, the code I'm using counts the MouseLButton down action - which means, because of the loop, the MouseLButton down keeps being registered. How would I make this code count the action as a single click and do nothing afterward until a user clicks again:</p>
  
  <p>OfficeManager.cpp:</p>
  
  <pre><code>void Hire::hireScreenNavigation()
  {
  if ((input-&gt;getMouseLButton()) &amp;&amp; (input-&gt;getMouseX() &gt; 900 &amp;&amp; input-&gt;getMouseX() &lt; 940) &amp;&amp; (input-&gt;getMouseY() &gt; 154 &amp;&amp; input-&gt;getMouseY() &lt; 174))
  {
      audio-&gt;playCue (CLICK_EXPAND);
      hire = true;
      Office.push_back (HireRecruitmentPool[0]);
      --officeCapacity;
  }
  
  if ((hireScreenSwitch==true) &amp;&amp; (input-&gt;getMouseX() &gt; 900 &amp;&amp; input-&gt;getMouseX() &lt; 940) &amp;&amp; (input-&gt;getMouseY() &gt; 154 &amp;&amp; input-&gt;getMouseY() &lt; 174))
  {
      SetCursor(LoadCursor(NULL,IDC_HAND));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the code in the Game class above (Game.cpp):</p>
  
  <pre><code>if(initialized)
  {
      switch( msg )
      {
          case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
          case WM_KEYDOWN: case WM_SYSKEYDOWN:
              input-&gt;keyDown(wParam);
              return 0;
          case WM_KEYUP: case WM_SYSKEYUP:
              input-&gt;keyUp(wParam);
              return 0;
          case WM_CHAR:
              input-&gt;keyIn(wParam);
              return 0;
          case WM_MOUSEMOVE:
              input-&gt;mouseIn(lParam);
              return 0;
          case WM_INPUT:
              input-&gt;mouseRawIn(lParam);
              return 0;
          case WM_LBUTTONDOWN:
              input-&gt;setMouseLButton(true);
              input-&gt;mouseIn(lParam);
              clicked = true;
              return 0;
          case WM_LBUTTONUP:
              input-&gt;setMouseLButton(false);
              input-&gt;mouseIn(lParam);
              return 0;
          case WM_MBUTTONDOWN:
              input-&gt;setMouseMButton(true);
              input-&gt;mouseIn(lParam);
              return 0;
          case WM_MBUTTONUP:
              input-&gt;setMouseMButton(false);
              input-&gt;mouseIn(lParam);
              return 0;
          case WM_RBUTTONDOWN:
              input-&gt;setMouseRButton(true);
              input-&gt;mouseIn(lParam);
              return 0;
          case WM_RBUTTONUP:
              input-&gt;setMouseRButton(false);
              input-&gt;mouseIn(lParam);
              return 0;
      }
  }
  return DefWindowProc( hwnd, msg, wParam, lParam );
  </code></pre>
  
  <p>If anyone has any examples on how to code it so that the hire functionality above counts a single click within those coordinates (instead of mouse down), I would be extremely appreciative. Keep in mind the coordinates for the hotspots will be different for each button in the game.</p>
  
  <p>Thanks!</p>