title: WinAPI mouse click does not work properly
body: <p>I am creating program in C++ (Windows 7 ), that controls one specific window by reading its screen and sending back mouse signals (only left-clicks). I am using WinAPI obviously. Problem is with the mouse signals. My target is to send mouse events independently on actual cursor position. (i.e. it can run on "the background" and the window does not have to be visible). </p>
  
  <p>I tried the obvious solution using SendMessage (or PostMessage):</p>
  
  <pre><code>PostMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
  this_thread::sleep_for (std::chrono::milliseconds(100));
  PostMessage(hwnd, WM_LBUTTONUP  , MK_LBUTTON, MAKELPARAM(x, y));
  </code></pre>
  
  <p>I think the commands work fine but there is some problem with how the application process the click events. It seems it does not take into account the parameters x,y and instead when <code>WM_LBUTTONUP</code> is called, it asks OS where the cursor is and make the click on that location. So in the end the click occurs always on the location of cursor (if it is inside the window).</p>
  
  <p>I also tried to send <code>WM_MOUSEMOVE</code> event before <code>WM_LBUTTONUP</code> but it didn't help.</p>
  
  <p>This behavior is really strange, and I fully blame the application not WinAPI. Any ideas how to solve this? Can I maybe somehow trick the window so it thinks that cursor is elsewhere?</p>