{"id":170,"date":"2025-06-03T17:40:18","date_gmt":"2025-06-04T10:10:17","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=170"},"modified":"2025-06-04T17:40:18","modified_gmt":"2025-06-04T10:10:17","slug":"pyautogui-python%e6%8e%a7%e5%88%b6%e9%9b%bb%e8%85%a6-%e6%8c%89%e9%8d%b5%e7%b2%be%e9%9d%88-%e9%8d%b5%e7%9b%a4%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/pyautogui-python%e6%8e%a7%e5%88%b6%e9%9b%bb%e8%85%a6-%e6%8c%89%e9%8d%b5%e7%b2%be%e9%9d%88-%e9%8d%b5%e7%9b%a4%e6%8e%a7%e5%88%b6\/","title":{"rendered":"2025 \u5e74\u6700\u65b0 PyAutoGUI \u6559\u5b78\uff1aPython \u63a7\u5236\u96fb\u8166\u7684\u6309\u9375\u7cbe\u9748\u8207\u9375\u76e4\u81ea\u52d5\u5316"},"content":{"rendered":"<p>&#8220;`html<\/p>\n<h1>2025 \u5e74\u6700\u65b0 PyAutoGUI \u6559\u5b78\uff1aPython \u63a7\u5236\u96fb\u8166\u7684\u6309\u9375\u7cbe\u9748\u8207\u9375\u76e4\u81ea\u52d5\u5316<\/h1>\n<h2>PyAutoGUI \u7c21\u4ecb<\/h2>\n<p>PyAutoGUI \u662f Python \u7684\u4e00\u500b\u5f37\u5927\u6a21\u7d44\uff0c\u80fd\u5920\u81ea\u52d5\u63a7\u5236\u9375\u76e4\u548c\u6ed1\u9f20\u7684\u64cd\u4f5c\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u81ea\u52d5\u5316\u6e2c\u8a66\u3001\u91cd\u8907\u6027\u4efb\u52d9\u57f7\u884c\u7b49\u5834\u666f\u3002\u9019\u500b\u8de8\u5e73\u53f0\u7684 GUI \u81ea\u52d5\u5316\u6a21\u7d44\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5927\u5e45\u5ea6\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p>\u6b32\u4e86\u89e3\u66f4\u591a\u95dc\u65bc PyAutoGUI \u7684\u6280\u8853\u7d30\u7bc0\uff0c\u8acb\u53c3\u95b1\u5b98\u65b9\u6587\u6a94\uff1a<a href=\"https:\/\/pypi.org\/project\/PyAutoGUI\/\" title=\"pyautogui\u5b98\u7db2\u6280\u8853\u4ecb\u7d39\" target=\"_blank\" rel=\"noopener\">PyAutoGUI \u5b98\u7db2\u6280\u8853\u4ecb\u7d39<\/a>\uff0c\u4ee5\u53ca\u5176 GitHub \u9801\u9762\uff1a<a href=\"https:\/\/github.com\/asweigart\/pyautogui\" title=\"pyautogui github\" target=\"_blank\" rel=\"noopener\">PyAutoGUI GitHub<\/a>\u3002<\/p>\n<h2>PyAutoGUI \u74b0\u5883\u5b89\u88dd<\/h2>\n<h3>\u4f7f\u7528 pip \u5b89\u88dd<\/h3>\n<p>\u5c0d\u65bc Python 2.7 \u7528\u6236\uff1a<\/p>\n<pre><code class=\"line-numbers\">pip install pyautogui\n<\/code><\/pre>\n<p>\u5c0d\u65bc Python 3.7 \u53ca\u4ee5\u4e0a\u7248\u672c\u7528\u6236\uff1a<\/p>\n<pre><code class=\"line-numbers\">pip3 install pyautogui\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/1HHpoKg.gif\" alt=\"Python\u63a7\u5236\u96fb\u8166\" title=\"\"><\/p>\n<p>\u5716\u7247\u8aaa\u660e\uff1aPyAutoGUI \u7684\u57fa\u672c\u64cd\u4f5c\u793a\u7bc4\u3002<\/p>\n<h2>PyAutoGUI \u7684\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<h3>\u9375\u76e4\u64cd\u4f5c\u8a9e\u6cd5<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u9375\u76e4\u64cd\u4f5c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\"># \u8f38\u5165\u6587\u5b57\npyautogui.typewrite('Hello world!')\n# \u6bcf\u6b21\u8f38\u5165\u9593\u96940.25\u79d2\npyautogui.typewrite('Hello world!', interval=0.25)\n# \u8f38\u5165\u591a\u500b\u6309\u9375\npyautogui.typewrite(['a', 'b', 'c', 'd'], interval=0.3)\n# \u6309\u4e0b\u55ae\u4e00\u6309\u9375\npyautogui.press('enter')\n# \u9023\u7e8c\u6309\u5de6\u9375\npyautogui.press(['left', 'left', 'left'])\n# \u6309\u4e0b `shift` \u9375\npyautogui.keyDown('shift')\n# \u9b06\u958b `shift` \u9375\npyautogui.keyUp('shift')\n# \u7d44\u5408\u9375\u64cd\u4f5c\npyautogui.hotkey('shift', 'command', 'left')\npyautogui.hotkey('command', 'c')  # \u8907\u88fd\npyautogui.hotkey('command', 'v')  # \u8cbc\u4e0a (Windows \u7cfb\u7d71\u6539\u70ba ctrl)\n<\/code><\/pre>\n<h3>\u5be6\u4f5c\u7bc4\u4f8b\uff1a\u8907\u88fd\u4e26\u8cbc\u4e0a\u6587\u672c<\/h3>\n<p>\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u793a\u7bc4\u5982\u4f55\u4f7f\u7528 PyAutoGUI \u8907\u88fd\u4e00\u6bb5\u6587\u672c\u4e26\u5c07\u5176\u8cbc\u4e0a\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">from pyautogui import press\nimport time\nimport pyautogui\n\n# \u8f38\u5165\u6587\u672c\npyautogui.typewrite('Hello world!')\npyautogui.typewrite('Hello world!', interval=0.25)\n# \u8907\u88fd\u6587\u672c\npyautogui.hotkey('shift', 'command', 'left')\npyautogui.hotkey('command', 'c')  # \u8907\u88fd\npyautogui.press('right')\npyautogui.press('enter')\n# \u8cbc\u4e0a\u6587\u672c\npyautogui.hotkey('command', 'v')  # \u8cbc\u4e0a\n<\/code><\/pre>\n<h3>\u5e38\u898b\u554f\u984c\u53ca\u7591\u96e3\u6392\u89e3<\/h3>\n<p>\u5982\u679c\u5728\u4f7f\u7528 PyAutoGUI \u6642\u9047\u5230\u554f\u984c\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd\u4f60\u7684 Python \u74b0\u5883\u5df2\u6b63\u78ba\u5b89\u88dd PyAutoGUI\u3002<\/li>\n<li>\u5728 Mac \u7cfb\u7d71\u4e2d\uff0c\u8acb\u78ba\u8a8d\u5df2\u6388\u4e88\u5fc5\u8981\u7684\u8f14\u52a9\u529f\u80fd\u6b0a\u9650\u3002<\/li>\n<li>\u5982\u7121\u6cd5\u63a7\u5236\u6ed1\u9f20\uff0c\u8acb\u6aa2\u67e5\u662f\u5426\u6709\u5176\u4ed6\u7a0b\u5f0f\u6b63\u5728\u4f54\u7528\u6ed1\u9f20\u3002<\/li>\n<\/ul>\n<h3>Domo<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/XanVwAx.gif\" alt=\"Python\u63a7\u5236\u9375\u76e4\" title=\"\"><\/p>\n<p>\u5716\u7247\u8aaa\u660e\uff1a\u4f7f\u7528 PyAutoGUI \u63a7\u5236\u9375\u76e4\u7684\u793a\u7bc4\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>PyAutoGUI \u53ef\u4ee5\u7528\u65bc\u591a\u7a2e\u81ea\u52d5\u5316\u4efb\u52d9\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u81ea\u52d5\u586b\u5beb\u8868\u55ae<\/li>\n<li>\u81ea\u52d5\u5316\u6e2c\u8a66\u61c9\u7528\u7a0b\u5f0f<\/li>\n<li>\u81ea\u52d5\u5316\u8655\u7406\u91cd\u8907\u6027\u5de5\u4f5c<\/li>\n<\/ul>\n<p>\u66f4\u591a Python \u6587\u7ae0\u53ef\u4ee5\u53c3\u8003\uff1a<a href=\"https:\/\/badgameshow.com\/steven\/python\/python-\u7b46\u8a18\" target=\"_blank\" rel=\"noopener\">Python \u6aa2\u67e5 dict \u662f\u5426\u6709\u9019\u500b key<\/a>\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u900f\u904e\u672c\u6587\uff0c\u4f60\u61c9\u8a72\u80fd\u5920\u638c\u63e1 PyAutoGUI \u7684\u57fa\u672c\u5b89\u88dd\u8207\u4f7f\u7528\u65b9\u6cd5\uff0c\u4e26\u80fd\u5920\u958b\u59cb\u81ea\u5df1\u7684\u81ea\u52d5\u5316\u4efb\u52d9\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. PyAutoGUI \u53ef\u4ee5\u7528\u5728\u54ea\u4e9b\u5834\u666f\uff1f<\/h3>\n<p>PyAutoGUI \u9069\u5408\u7528\u65bc\u81ea\u52d5\u5316\u6e2c\u8a66\u3001\u91cd\u8907\u6027\u5de5\u4f5c\u3001\u81ea\u52d5\u586b\u5beb\u8868\u55ae\u7b49\u5834\u666f\u3002<\/p>\n<h3>2. \u5982\u4f55\u89e3\u6c7a PyAutoGUI \u7121\u6cd5\u63a7\u5236\u6ed1\u9f20\u7684\u554f\u984c\uff1f<\/h3>\n<p>\u8acb\u78ba\u8a8d\u6388\u4e88\u4e86 PyAutoGUI \u9700\u8981\u7684\u8f14\u52a9\u529f\u80fd\u6b0a\u9650\uff0c\u4e26\u6aa2\u67e5\u662f\u5426\u6709\u5176\u4ed6\u7a0b\u5f0f\u4f54\u7528\u4e86\u6ed1\u9f20\u63a7\u5236\u6b0a\u3002<\/p>\n<h3>3. PyAutoGUI \u662f\u5426\u652f\u6301 Mac \u548c Windows \u7cfb\u7d71\uff1f<\/h3>\n<p>\u662f\u7684\uff0cPyAutoGUI \u652f\u6301\u8de8\u5e73\u53f0\u4f7f\u7528\uff0c\u5305\u62ec Mac \u548c Windows \u7cfb\u7d71\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pyautogui \u662f python\u7684\u4e00\u500b\u6a21\u7d44\uff0c\u4ed6\u80fd\u63a7\u5236\u9375\u76e4\u548c\u6ed1\u9f20\u7684\u64cd\u4f5c\uff0c\u80fd\u5229\u7528\u5b83\u505a\u81ea\u52d5\u5316\u64cd\u4f5c\uff0c\u50cf\u662f\u7528\u5728\u8edf\u9ad4\u6e2c\u8a66\u3001\u91cd\u8907\u6027\u52d5\u4f5c\u7b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[31,33,32],"class_list":["post-170","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-pyautogui","tag-33","tag-32"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/11\/cup-1-1.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-2K","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":10,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":13080,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/170\/revisions\/13080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/559"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}