Emulating human-like mouse movements

Does anyone know of an algorithm in which to do this?
The WIN32 API just allows the cursor to jump to one part of the screen rather than move there like a human would do.

For it to be human-like it would have varying speeds of mouse movement, an imperfect path to the target and would overshoot the target occasionally.

One thing I I've written (But haven't actually tested yet) is creating a for loop to move the cursor up one pixel at a time.
E.G
1
2
3
4
for (int temp = 0; temp < 2000; temp++, y++)
  {
    SetCursorPos(x, y);
  }
As a couple of ideas, you could use the bresenham algoritm to calculate the position of the cursor between the start and end points (or just use a line slope calculation) but to get more realistic movements you could use some splines, some examples can be found here:

http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/opengl_programming.html

By setting several control points I guess it could look quite convincing.
You would just add a certain amount to the x or y value depending on how fast you are moving the mouse ect. To move it faster you would simply increase the amount the x and y value is incremented by. You just jump to the new position but you jump in small steps so it seems it glides like a actual mouse does. In games when objects are moving all they are doing is "jumping" to a new position. Its just such a small jump the eye perceives it like a smooth movement. The mouse cursor is no different.

Its hard to elaborate unless you specifically state what you are trying to do. I take it you are either making a mouse movement recorder, a custom mouse or something else similar.
Last edited on
Topic archived. No new replies allowed.