A support request came in today asking how to show the mouse moving from one point to another slowly enough to be visible in a video demo.
The regular MouseMove function simply “jumps” the mouse cursor straight to the given point, without passing any points between wherever it was to start with and that end point. So the question was how to specify a start point and an end point and show the mouse moving on a line between them.
To achieve this we need to determine what that line is. We don’t want to move to *every* point between those two points on both the x and y axis. So how do we do it?
Well, it was a long time ago but deep in the recesses of my mind was a little equation we learnt in mathematics at school. I admit I had to look it up. It was the “slope-intercept” equation:
y = mx + b
The slope “m” is the change in y over the change in x:
m = (y2 – y1) / (x2 – x1)
Once we have that we can calculate b (the y-intercept) given a known point (e.g. the start point) and then for each x we can calculate y.
So here’s a script which will move the mouse slowly through the line between two given points:
Let>startX=20 Let>startY=100 Let>endX=300 Let>endY=400 Let>delay_interval=0.001 //remember school math? //equation of a line is y = mx+b //m = y2-y1 / x2-x1 Let>m={(%endY%-%startY%)/(%endX%-%startX%)} //b = y-mx Let>b={%startY%-(%m% * %startX%)} Let>x=startX Let>y=startY Repeat>x //y = mx+b Let>y={Trunc((%m% * %x%) + %b%)} MouseMove>x,y Wait>delay_interval If>endX>startX Let>x=x+1 Else Let>x=x-1 Endif Until>x=endX
This probably isn’t much use to most people, but it’s a little bit of fun. Maybe you can jazz up your scripts to animate the movement of the cursor or something 🙂
Doing anything a little bit out of the ordinary with Macro Scheduler? Let me know.