title: PostMessage mouse click to background window
body: <p>I've seen a lot of threads about this directing to SendInput, but that doesn't work in this case.</p>
  
  <p>I'm trying to send a mouse click to a certain location to a background window (game).</p>
  
  <p>I can successfully send a mouse click to a background window using PostMessage, but I need to externally set the mouse position for it to work.</p>
  
  <pre><code>[DllImport("user32.dll")]
  static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
  
  const int WM_LBUTTONDOWN = 0x0201;
  const int WM_LBUTTONUP = 0x0202;
  
  PostMessage(hWnd, WM_LBUTTONDOWN, 1, 0);
  PostMessage(hWnd, WM_LBUTTONUP, 0, 0);
  </code></pre>
  
  <p>I've also tried extending with point</p>
  
  <pre><code>public int MakeLParam(int LoWord, int HiWord)
  {
      return (int)((HiWord &lt;&lt; 16) | (LoWord &amp; 0xFFFF));
  }
  
  PostMessage(hWnd, WM_LBUTTONDOWN, 1, MakeLParam(pt.X, pt.Y));
  </code></pre>
  
  <p>But nothing seems to work.
  Is it possible to set location via PostMessage or do I have to do it externally, then click, then set cursor back to original position?</p>
  
  <p>Any help is appreciated.</p>