title: Moving mouse cursor programmatically
body: <p>To start out I found this code at <a href="http://swigartconsulting.blogs.com/tech_blender/2005/08/how_to_move_the.html" rel="noreferrer">http://swigartconsulting.blogs.com/tech_blender/2005/08/how_to_move_the.html</a>:</p>
  
  <pre><code>public class Win32
  {
      [DllImport("User32.Dll")]
      public static extern long SetCursorPos(int x, int y);
  
      [DllImport("User32.Dll")]
      public static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
  
      [StructLayout(LayoutKind.Sequential)]
      public struct POINT
      {
          public int x;
          public int y;
      }
  }
  </code></pre>
  
  <p>Paste the following code in the button's click eventhandler:</p>
  
  <pre><code>Win32.POINT p = new Win32.POINT();
  p.x = button1.Left + (button1.Width / 2);
  p.y = button1.Top + (button1.Height / 2);
  
  Win32.ClientToScreen(this.Handle, ref p);
  Win32.SetCursorPos(p.x, p.y);
  </code></pre>
  
  <p>This will move the mouse pointer to the center of the button.</p>
  
  <p>This code works great, but I can't seem to figure out how to extend it a bit.  Let's say I have internet explorer (embedded in a windows form) open to a web page (some random page I don't know about before hand) with a drop down list box in it.  I've modified the above code to move the cursor over and get the list box to drop down(using the mouse click method shown below to drop the list down), and also move up and down the list highlighting each item as the mouse pointer goes over, but for the life of me I cannot figure out how to actually make the mouse click on the currently selected item to keep the selection.  The way I'm doing it now the drop down list box just closes and the selection isn't changed.  I'm using the following code for the mouse click (which does get the list to drop down):</p>
  
  <pre><code>private static void MouseClick(int x, int y, IntPtr handle) //handle for the browser window
  {
      IntPtr lParam = (IntPtr)((y &lt;&lt; 16) | x); // The coordinates
      IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
  
      const uint downCode = 0x201; // Left click down code
      const uint upCode = 0x202; // Left click up code
  
      SendMessage(handle, downCode, wParam, lParam); // Mouse button down
      SendMessage(handle, upCode, wParam, lParam); // Mouse button up
  }
  </code></pre>
  
  <p>I'm sure I'm missing something simple here, but for the life of me cannot figure out what it is.  Thanks in advance everyone.</p>
  
  <p>Bob</p>