{"id":7256,"date":"2024-09-21T18:33:53","date_gmt":"2024-09-21T10:33:53","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=7256"},"modified":"2024-09-21T18:33:53","modified_gmt":"2024-09-21T10:33:53","slug":"%e5%90%ac%e8%af%b4%e4%bd%a0%e7%94%a8%e7%9a%84%e6%98%af-windows-%e7%b3%bb%e7%bb%9f%ef%bc%8c%e7%9b%98%e5%ae%83%ef%bc%81","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=7256","title":{"rendered":"\u542c\u8bf4\u4f60\u7528\u7684\u662f Windows \u7cfb\u7edf\uff0c\u76d8\u5b83\uff01"},"content":{"rendered":"\n<p>\u5c0f\u5e05b\u4e4b\u524d\u5206\u4eab\u8fc7 <a target=\"_blank\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=Mzg2NzYyNjg2Nw==&amp;mid=2247490166&amp;idx=1&amp;sn=7e224d461bed7d647bb946ab92205c89&amp;chksm=ceb9e06af9ce697c8f809c08e21334fff9aa9293e63c91c332f8980e4bc20c04fdcc50049099&amp;token=1076685549&amp;lang=zh_CN&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">pyauogui<\/a>, \u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u5e2e\u4f60\u64cd\u4f5c\u4e00\u4e9b\u91cd\u590d\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\u7ed9\u4f60\u5206\u4eab\u7684\u4e5f\u662f\u81ea\u52a8\u5316\u7684\u5e93 \u2014\u2014 pywinauto\uff0c\u8fd9\u4e2a\u9002\u5408\u5728\u4f60\u7684 Windows \u7cfb\u7edf\u64cd\u4f5c\uff0c\u5b83\u53ef\u4ee5\u7528\u4ee3\u7801\u63a7\u5236\u4f60\u7684\u9f20\u6807\u548c\u952e\u76d8\uff0c\u5173\u952e\u662f\u5b83\u53ef\u4ee5\u66f4\u7cbe\u51c6\u7684\u83b7\u53d6\u4f60\u8981\u64cd\u4f5c\u7684\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<h2>\u90a3\u4e48\u600e\u4e48\u73a9\u5462\uff1f<\/h2>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u5b66\u4e60 Python \u7684\u6b63\u786e\u59ff\u52bf\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pica.zhimg.com\/80\/v2-8529dbec66d5e297629f59dce579c8c8_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u9996\u5148\u4f60\u9700\u8981\u5b89\u88c5 pywinauto:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>pip install -U pywinauto<\/p>\n<\/blockquote>\n\n\n\n<p>\u5b89\u88c5\u597d\u4e4b\u540e\u4f60\u5c31\u53ef\u4ee5\u9020\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/picx.zhimg.com\/80\/v2-6265f35fb78c7604dd2f8a6a640b6c07_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u6bd4\u5982\u4f60\u8981\u901a\u8fc7\u4ee3\u7801\u6253\u5f00\u4f60\u7684 Pycharm \uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>from pywinauto import Application pycharm_path = r&#8221;D:\\PyCharm Community Edition 2023.2.2\\bin\\pycharm64.exe&#8221; app = Application(backend=&#8221;uia&#8221;).start(pycharm_path)<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u91cc\u4f7f\u7528\u4e86 Pywinauto \u5e93\u4e2d\u7684 Application \u7c7b\u7684 start() \u65b9\u6cd5\u6765\u542f\u52a8 PyCharm \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<p>backend=&#8221;uia&#8221; \u53c2\u6570\u6307\u5b9a\u4e86\u4f7f\u7528 UI Automation \u6280\u672f\u6765\u4e0e\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n\n\n\n<p>\u8fd0\u884c\u8d77\u6765\u5c31\u4f1a\u81ea\u52a8\u6253\u5f00 Pycharm\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/picx.zhimg.com\/80\/v2-90ff9ba78544fa704f85a89b2eeab55d_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u597d\u5bb6\u4f19\uff0c\u5728 vscode \u6253\u5f00 Pycharm \u662f\u5427\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-ea2509e464d38915506af4e3c91d3254_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u4f60\u8fd8\u53ef\u4ee5\u8ba9\u5b83\u76f4\u63a5\u5728\u91cc\u9762\u5199\u4e1c\u897f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pica.zhimg.com\/80\/v2-1a6db4e2d76edc4f2b250d97cd59db35_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u8fd0\u884c\u8d77\u6765\u5c31\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pica.zhimg.com\/80\/v2-e2f2e3bd2b4efb19d5c7ff5168f1fb0b_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u5176\u5b9e\u5173\u952e\u5c31\u662f\u8981\u627e\u5230\u4f60\u8981\u64cd\u4f5c\u7684\u7a97\u53e3\uff0c\u7136\u540e\u53bb\u505a\u4e00\u4e9b\u5177\u4f53\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h2>\u8fd9\u91cc\u5c31\u518d\u4ecb\u7ecd\u4e00\u4e2a\u795e\u5668 \u2014\u2014\u2014 SWAPY\u3002<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-aa54ea55246ac36e575fcd7460870f52_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u8fd0\u884c\u8d77\u6765\u4f60\u4f1a\u53d1\u73b0\u5b83\u53ef\u4ee5\u76d1\u542c\u5230\u4f60\u5728\u7535\u8111\u4e0a\u8fd0\u884c\u7684\u7a97\u53e3\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-d4a24de613eabdaf6f756cafc01c78a7_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5355\u51fb\u4f60\u60f3\u8981\u64cd\u4f5c\u7684\u7a0b\u5e8f\uff0c\u53f3\u4e0b\u89d2\u5c31\u4f1a\u663e\u793a\u8fd9\u4e2a\u7a0b\u5e8f\u76f8\u5e94\u7684\u53c2\u6570\u503c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/picx.zhimg.com\/80\/v2-c8b54a3f61d13983c07f052b90eec426_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u6bd4\u5982\u6211\u521a\u521a\u8981\u64cd\u4f5c Pycharm \u7684\u7a97\u53e3\uff0c\u5c31\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>app = Application().Connect(title=u&#8217;pythonProject \\u2013 main.py&#8217;, class_name=&#8217;SunAwtFrame&#8217;)<\/p>\n<\/blockquote>\n\n\n\n<p>\u8d34\u5fc3\u7684\u662f\uff0c\u4f60\u53ea\u8981\u5bf9\u7740\u4f60\u8981\u64cd\u4f5c\u7684\u7a0b\u5e8f\u7a97\u53e3\u70b9\u51fb\u53f3\u952e\uff0c\u7136\u540e\u70b9\u51fb\u8fde\u63a5\uff0c\u5b83\u53f3\u4e0a\u89d2\u76f4\u63a5\u5e2e\u4f60\u751f\u6210\u7684\u8fde\u63a5\u4ee3\u7801\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/picx.zhimg.com\/80\/v2-c441008d61e02dc1b7f0a45bd1a51637_720w.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u8fd9\u6837\u4f60\u5c31\u518d\u4e5f\u4e0d\u7528\u4e00\u8fb9\u5199\u4ee3\u7801\u4e00\u8fb9\u53bb\u627e\u7a97\u53e3\u7684\u5c5e\u6027\u4e86\u3002<\/p>\n\n\n\n<p>\u6211\u628a SWAPY \u653e\u5728\u4ee5\u4e0b\u8fd9\u91cc\u4e86\uff0c\u4f60\u53ef\u4ee5\u81ea\u884c\u4e0b\u8f7d\u4f7f\u7528\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/pan.quark.cn\/s\/4d617f275f3c\n<\/div><\/figure>\n<\/blockquote>\n\n\n\n<h2>pywinauto \u7684\u9f20\u6807\u548c\u952e\u76d8\u64cd\u4f5c<\/h2>\n\n\n\n<p>\u548c Pyautogui \u7c7b\u4f3c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 click \u7684\u76f8\u5173\u65b9\u6cd5\u5bf9\u9f20\u6807\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/picx.zhimg.com\/80\/v2-c471b6beea90096798ab0f92232306b4_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<p>\u952e\u76d8\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-200592b8fe8ea79d98296c5386acb876_720w.webp\" alt=\"\"\/><figcaption class=\"wp-element-caption\">\u6dfb\u52a0\u56fe\u7247\u6ce8\u91ca\uff0c\u4e0d\u8d85\u8fc7 140 \u5b57\uff08\u53ef\u9009\uff09<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>&#8216;+&#8217;: \u4ee3\u8868 SHIFT &#8216;^&#8217;: \u4ee3\u8868 Ctrl &#8216;%&#8217;: \u4ee3\u8868 ALT<\/p>\n<\/blockquote>\n\n\n\n<p>\u6bd4\u5982\u8fd9\u6837 send_keys(&#8216;^a^c&#8217;) \u5c31\u662f Ctrl+A\u3002<\/p>\n\n\n\n<p>\u5b98\u65b9\u6587\u6863\u5728\u8fd9\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/pywinauto.readthedocs.io\/\n<\/div><\/figure>\n<\/blockquote>\n\n\n\n<h2>pywinauto \u83b7\u53d6\u6570\u636e<\/h2>\n\n\n\n<p>\u6700\u540e\u518d\u989d\u5916\u8bf4\u4e00\u4e0b\uff0c pywinauto \u8fd8\u53ef\u4ee5\u83b7\u53d6\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u83b7\u53d6\u4f60\u8bb0\u4e8b\u672c\u7684\u5185\u5bb9\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em># \u542f\u52a8\u8bb0\u4e8b\u672c\u5e94\u7528\u7a0b\u5e8f<\/em>\n app = Application().start(\"notepad.exe\")\n time.sleep(1)\n <em># \u9009\u62e9\u8bb0\u4e8b\u672c\u4e3b\u7a97\u53e3<\/em>\n main_window = app.window(title=\"\u65e0\u6807\u9898 - \u8bb0\u4e8b\u672c\")\n <em># \u83b7\u53d6\u7f16\u8f91\u6846\u63a7\u4ef6\u5e76\u83b7\u53d6\u6587\u672c\u5185\u5bb9<\/em>\n edit_control = main_window.Edit\n text = edit_control.window_text()\n print(\"\u8bb0\u4e8b\u672c\u6587\u672c\u5185\u5bb9:\", text)<\/pre>\n\n\n\n<p>OK, \u90a3\u4e48\u4ee5\u4e0a\u5c31\u662f\u5c0f\u5e05b\u4eca\u5929\u7ed9\u4f60\u5e26\u6765\u7684\u5206\u4eab\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u5e2e\u52a9\u3002<\/p>\n\n\n\n<p>\u63a8\u8350\u9605\u8bfb\uff1a<\/p>\n\n\n\n<p><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=Mzg2NzYyNjg2Nw==&amp;mid=2247496926&amp;idx=1&amp;sn=023160552f77f7b0ebc0cb616b48ca7e&amp;chksm=ceba0ec2f9cd87d48f8d9f5a9e7c7cce78833a58954b585f93859336f053e0afd9c0cb73e4b4&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">\u5c0f\u5e05b\u516c\u4f17\u53f7\u90a3\u4e9b\u4e0d\u4e3a\u4eba\u77e5\u7684\u5173\u952e\u8bcd<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u5e05b\u4e4b\u524d\u5206\u4eab\u8fc7 pyauogui, \u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u5e2e\u4f60\u64cd\u4f5c\u4e00\u4e9b\u91cd\u590d\u7684\u64cd\u4f5c\u3002 \u4eca\u5929\u7ed9\u4f60\u5206\u4eab\u7684\u4e5f\u662f\u81ea\u52a8\u5316\u7684\u5e93 \u2014\u2014 pywinauto\uff0c\u8fd9\u4e2a\u9002\u5408\u5728\u4f60\u7684 Windows \u7cfb\u7edf\u64cd\u4f5c\uff0c\u5b83\u53ef\u4ee5\u7528\u4ee3\u7801\u63a7\u5236\u4f60\u7684\u9f20\u6807\u548c\u952e\u76d8\uff0c\u5173\u952e\u662f\u5b83\u53ef\u4ee5\u66f4\u7cbe\u51c6\u7684\u83b7\u53d6\u4f60\u8981\u64cd\u4f5c\u7684\u7ec4\u4ef6\u3002 \u90a3&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[303],"tags":[],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/7256"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7256"}],"version-history":[{"count":1,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/7256\/revisions"}],"predecessor-version":[{"id":7257,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/7256\/revisions\/7257"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}