title: "mouse_event" function - sending cursor to (slightly) wrong coordinates
body: <p>The mouse_event function sends the cursor to slightly wrong coordinates (1-20 pixels off).  The degree of how much it is "off" is based on a pattern I can't quite figure out.  </p>
  
  <p>Here is my code</p>
  
  <pre><code>int x, y;
  int repeats = 1000;
  int start = 0;
  POINT pt;
  
  for(int i=0; i&lt;repeats; i+=10) //first loop, down right
  {
      x = (65536 / 1920) * i - 1; //convert to absolute coordinates
      y = (65536 / 1080) * i - 1;
      mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0); //move
      GetCursorPos(&amp;pt); //get cursor position
      if(pt.x != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);} //check if the position is wrong, and if so fix it.
      if(pt.y != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
      cout &lt;&lt; "Try: " &lt;&lt; i &lt;&lt; ", " &lt;&lt; i &lt;&lt; "\tReal: " &lt;&lt; pt.x &lt;&lt; ", " &lt;&lt; pt.y &lt;&lt; "\tDiff: " &lt;&lt; pt.x - i &lt;&lt; ", " &lt;&lt; pt.y - i &lt;&lt; '\n';
  }
  
      for(int i=repeats; i&gt;0; i-=10) //second loop, up left
  {
      x = (65536 / 1920) * i - 1;
      y = (65536 / 1080) * i - 1;
      mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
      GetCursorPos(&amp;pt);
      if(pt.x != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
      if(pt.y != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
      cout &lt;&lt; "Try: " &lt;&lt; i &lt;&lt; ", " &lt;&lt; i &lt;&lt; "\tReal: " &lt;&lt; pt.x &lt;&lt; ", " &lt;&lt; pt.y &lt;&lt; "\tDiff: " &lt;&lt; pt.x - i &lt;&lt; ", " &lt;&lt; pt.y - i &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>If this is run it results in the mouse moving down and right from the top left of the screen, then back up again.  But the further down it goes, the more incorrect the mouse movements created by "mouse_event" end up being.  </p>
  
  <p>I move it, then record the current coordinates, then calculate the difference.  The difference (the error in movements) increases the further down the screen I go.  I've even tried to add an additional check which tests if the coordinates are off, then tries to move the mouse to the right spot again but it isn't working</p>
  
  <p>Any idea why this might be?  </p>
  
  <p>Here is a log of the output for this program for convenience. </p>
  
  <p><a href="http://puu.sh/34VER.txt" rel="noreferrer">Output_Log.txt</a></p>
  
  <p>It clearly shows that in the first loop (which moves the mouse down and right) the error increases, then on the second loop (which moves it back up and left again) the error decreases in the same way.</p>
  
  <p>Any idea why this might be happening?  It happens on more complex implementations as well in ways I can't quantify and which are unlike this one, so I think it must be within the mouse_event function itself or some feature I don't understand</p>
  
  <p>Thanks in advance for any help</p>