Question

I need to test a software that treats some mouse movements as "gestures". For such a task I need to emulate mouse movement from point A to point B, not in straight line, but as a real mouse moves - with curves, a bit of jaggedyness etc. Is there any available solution (algorithm/code itself, not a library/exe) that I can use?

Of course I can write some simple sinusoidal math by myself, but this would be a very crude emulation of a human hand leading a mouse. Perhaps such a task has been solved already numerous times, and I can just borrow an existing code? :)

Was it helpful?

Solution

Take a look at the Mouse.simba file which is part of the SRL Framework, a macro program designed to work with online games like Runescape. Runescape has extensive macro detection capabilities so all parts of the SRL Framework have been developed to look as human as possible - the mouse functions in particular.

The code is in Pascal but should be quite easy to read. Look at the MMouse() procedure by BenLand100 it moves very realistically doing advanced movements like loops and overshooting its target as well as continuously varying accelerations and directions (also now has laptop touchpad type movements). If you want to test it you'll need to download SIMBA and enable the SRL-include.

OTHER TIPS

How about recording some real gestures and making a way to play them back? That's going to be as real as anything you can synthesize, and it would be repeatable (which is nice for testing).

Create a simple test app which shows a random positioned dot every two seconds. Follow the dot yourself and record your natural mouse movements.

One way to capture this behaviour could be to define an invisible "grid" on the screen, where you track which squares the mouse moves through on its journey.

If this part works and records properly, there's no need to bombard it with tests, since you know that each grid square does its job. Interpreting the gesture is also made easier with this.

For anyone in the future: I developed a library for Java, that does exactly what OP is asking. The noise/jaggedness in movement, sinusoidal arcs, overshooting the position a bit, etc. Plus the library is written with extension and configuration possibilities in mind, so anyone can fine tune it, if the default solution is not matching the case. Available from Maven Central now.

https://github.com/JoonasVali/NaturalMouseMotion

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top