{"id":1438,"date":"2011-01-18T13:33:06","date_gmt":"2011-01-18T13:33:06","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/?p=1438"},"modified":"2011-01-18T13:33:06","modified_gmt":"2011-01-18T13:33:06","slug":"slow-mouse-move","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2011\/01\/18\/slow-mouse-move\/","title":{"rendered":"Slow Mouse Move"},"content":{"rendered":"<p>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.  <\/p>\n<p>The regular MouseMove function simply &#8220;jumps&#8221; 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.<\/p>\n<p>To achieve this we need to determine what that line is.  We don&#8217;t want to move to *every* point between those two points on both the x and y axis.  So how do we do it?<\/p>\n<p>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 &#8220;slope-intercept&#8221; equation:<\/p>\n<blockquote><p>y = mx + b<\/p><\/blockquote>\n<p>The slope &#8220;m&#8221; is the change in y over the change in x:<\/p>\n<blockquote><p>m = (y2 &#8211; y1) \/ (x2 &#8211; x1)<\/p><\/blockquote>\n<p>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.  <\/p>\n<p>So here&#8217;s a script which will move the mouse slowly through the line between two given points:<\/p>\n<pre name=\"code\" class=\"macroscript\">Let>startX=20\r\nLet>startY=100\r\nLet>endX=300\r\nLet>endY=400\r\nLet>delay_interval=0.001\r\n\r\n\/\/remember school math?\r\n\/\/equation of a line is y = mx+b\r\n\r\n\/\/m = y2-y1 \/ x2-x1\r\nLet>m={(%endY%-%startY%)\/(%endX%-%startX%)}\r\n\/\/b = y-mx\r\nLet>b={%startY%-(%m% * %startX%)}\r\n\r\nLet>x=startX\r\nLet>y=startY\r\nRepeat>x\r\n   \/\/y = mx+b\r\n   Let>y={Trunc((%m% * %x%) + %b%)}\r\n   MouseMove>x,y\r\n   Wait>delay_interval\r\n   If>endX>startX\r\n     Let>x=x+1\r\n   Else\r\n     Let>x=x-1\r\n   Endif\r\nUntil>x=endX<\/pre>\n<p>This probably isn&#8217;t much use to most people, but it&#8217;s a little bit of fun.  Maybe you can jazz up your scripts to animate the movement of the cursor or something \ud83d\ude42  <\/p>\n<p>Doing anything a little bit out of the ordinary with Macro Scheduler?  Let me know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;jumps&#8221; the mouse cursor straight to the given point, without passing any points between wherever it was to start with and that end [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1438"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=1438"}],"version-history":[{"count":5,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions"}],"predecessor-version":[{"id":1443,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1438\/revisions\/1443"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=1438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=1438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=1438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}