{"id":2211,"date":"2022-07-07T16:26:06","date_gmt":"2022-07-07T11:26:06","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2211"},"modified":"2022-07-07T16:26:09","modified_gmt":"2022-07-07T11:26:09","slug":"python3-automation-code-to-move-the-mouse-at-constant-speed","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/","title":{"rendered":"Python 3 Automation Code to Move the Mouse at Constant Speed"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">code.py<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import sys\nimport time\nimport win32api\n\nif (len(sys.argv) &lt; 4):\n\tprint &quot;Usage: python mousemove.py dx dy speed&quot;\n\tsys.exit()\n\ncurrent = win32api.GetCursorPos()\ncx = sx = current[0]\ncy = sy = current[1]\n\nmx = int(sys.argv[1])\nmy = int(sys.argv[2])\nvx = vy = int(sys.argv[3])\n\nprint &quot;Moving&quot;, mx, my, &quot;with&quot;, vx, &quot;pixels per second&quot;\nprint &quot;Press 'q' to quit&quot;\n\nlast = time.time()\n\nwhile(True):\n\tif win32api.GetAsyncKeyState(ord('Q')):\n\t\tsys.exit()\n\t\t\n\tcurrent = time.time()\n\ttick = current - last\n\tlast = current\n\t\n\tif mx &gt; 0:\n\t\tcx += vx * tick;\n\t\tif cx &gt; mx + sx or cx &lt; sx:\n\t\t\tvx = -vx;\n\t\t\tcx = max( sx, min( mx + sx, cx ) )\n\tif( my &gt; 0 ):\n\t\tcy += vy * tick;\n\t\tif cy &gt; my + sy or cy &lt; sy:\n\t\t\tvy = -vy;\n\t\t\tcy = max( sy, min( my + sy, cy ) )\n\t\n\twin32api.SetCursorPos((int(cx),int(cy)))\n\ttime.sleep(0.001)<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>code.py<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2211","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python 3 Automation Code to Move the Mouse at Constant Speed<\/title>\n<meta name=\"description\" content=\"code.py import sys import time import win32api if (len(sys.argv) &lt; 4): print &quot;Usage: python mousemove.py dx dy speed&quot; sys.exit() current =\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python 3 Automation Code to Move the Mouse at Constant Speed\" \/>\n<meta property=\"og:description\" content=\"code.py import sys import time import win32api if (len(sys.argv) &lt; 4): print &quot;Usage: python mousemove.py dx dy speed&quot; sys.exit() current =\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-07T11:26:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-07T11:26:09+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python 3 Automation Code to Move the Mouse at Constant Speed","description":"code.py import sys import time import win32api if (len(sys.argv) &lt; 4): print &quot;Usage: python mousemove.py dx dy speed&quot; sys.exit() current =","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/","og_locale":"en_US","og_type":"article","og_title":"Python 3 Automation Code to Move the Mouse at Constant Speed","og_description":"code.py import sys import time import win32api if (len(sys.argv) &lt; 4): print &quot;Usage: python mousemove.py dx dy speed&quot; sys.exit() current =","og_url":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-07T11:26:06+00:00","article_modified_time":"2022-07-07T11:26:09+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Python 3 Automation Code to Move the Mouse at Constant Speed","datePublished":"2022-07-07T11:26:06+00:00","dateModified":"2022-07-07T11:26:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/"},"wordCount":12,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/","url":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/","name":"Python 3 Automation Code to Move the Mouse at Constant Speed","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-07-07T11:26:06+00:00","dateModified":"2022-07-07T11:26:09+00:00","description":"code.py import sys import time import win32api if (len(sys.argv) &lt; 4): print &quot;Usage: python mousemove.py dx dy speed&quot; sys.exit() current =","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/python3-automation-code-to-move-the-mouse-at-constant-speed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python 3 Automation Code to Move the Mouse at Constant Speed"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2211"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2211\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}