{"id":279997,"date":"2021-01-11T15:26:44","date_gmt":"2021-01-11T07:26:44","guid":{"rendered":"http:\/\/4563.org\/?p=279997"},"modified":"2021-01-11T15:26:44","modified_gmt":"2021-01-11T07:26:44","slug":"python-%e5%9c%a8-windows-%e4%b8%8a%e6%a8%a1%e6%8b%9f%e9%bc%a0%e6%a0%87%e6%8c%89%e9%94%ae%e6%97%b6%e9%97%b4%e9%97%ae%e9%a2%98%ef%bc%8c%e5%ba%94%e8%af%a5%e5%b1%9e%e4%ba%8e%e5%be%88%e4%b8%93%e4%b8%9a","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=279997","title":{"rendered":"Python \u5728 windows \u4e0a\u6a21\u62df\u9f20\u6807\u6309\u952e\u65f6\u95f4\u95ee\u9898\uff0c\u5e94\u8be5\u5c5e\u4e8e\u5f88\u4e13\u4e1a\u7684\u95ee\u9898\u4e86"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u5728 windows \u4e0a\u6a21\u62df\u9f20\u6807\u6309\u952e\u65f6\u95f4\u95ee\u9898\uff0c\u5e94\u8be5\u5c5e\u4e8e\u5f88\u4e13\u4e1a\u7684\u95ee\u9898\u4e86               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6211\u7528 python \u5728 windows \u6a21\u62df\u9f20\u6807\u70b9\u51fb\u4e0e\u952e\u76d8\u8f93\u5165\uff0c\u4f7f\u7528\u7684\u662f win32api.mouse_event \u4e0e win32api.keybd_event \u4e24\u4e2a\u51fd\u6570\u3002\u6211\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff0c\u8fd9\u4e24\u4e2a\u51fd\u6570\u8fd0\u884c\u65f6\u95f4\u5728\u914d\u7f6e\u5dee\u7684\u7535\u8111\u4e0a\u662f 5ms\uff0c\u5728\u914d\u7f6e\u597d\u7684\u7535\u8111\u4e0a\u662f 15ms\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u60c5\u51b5\uff1f\u4e0d\u5e94\u8be5\u5728\u914d\u7f6e\u53f7\u7684\u7535\u8111\u4e0a\u6267\u884c\u66f4\u5feb\u5417\uff1f\u6211\u8fd9\u91cc\u7684\u524d\u63d0\u662f\u7a0b\u5e8f\u4e00\u6837\u3002\u8bf7\u95ee\u6709\u54ea\u4f4d\u53ef\u5e2e\u5e2e\u6211\uff0c\u6211\u60f3\u5728\u914d\u7f6e\u597d\u7684\u7535\u8111\u4e0a\u8fbe\u5230 5ms \u7684\u6548\u679c\uff0c\u56e0\u4e3a\u8fd8\u6709\u5176\u4ed6\u8ba1\u7b97\u8981\u8fdb\u884c\uff0c\u914d\u7f6e\u5dee\u7684\u5e26\u4e0d\u52a8\u3002\u914d\u7f6e\u5dee\u7684\u7535\u8111\u662f windows \u4f01\u4e1a\u7248\uff0c\u914d\u7f6e\u597d\u7684\u7535\u8111\u662f windows \u4e13\u4e1a\u7248\u3002\u5982\u679c\u6709\u5176\u4ed6\u6a21\u62df\u9f20\u6807\u952e\u76d8\u7684\u65b9\u5f0f\u53ef\u4ee5\u4ecb\u7ecd\u7ed9\u6211\uff0c\u8981\u6c42\u53ea\u6709\u4e00\u4e2a\u901f\u5ea6\u5feb\uff01<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\uff1a<br \/> # \u4e1a\u52a1\u4ee3\u7801<br \/> win32api.keybd_event(0x74, 0, 0, 0)<br \/> win32api.keybd_event(0x74, 0, win32con.KEYEVENTF_KEYUP, 0)<br \/> # \u4e1a\u52a1\u4ee3\u7801      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>19<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4938282\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zictos <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u80fd\u662f\u8ba1\u7b97\u8bef\u5dee\uff0c\u6216\u8005\u914d\u7f6e\u597d\u7684\u7535\u8111\u6709\u5176\u4ed6\u7a0b\u5e8f\u5360\u7528 cpu\uff0c\u53ef\u4ee5\u90fd\u5206\u522b\u88c5\u4e00\u4e2a\u5168\u65b0\u7684\u7cfb\u7edf\u518d\u8bd5\u8bd5\u3002\u4e5f\u53ef\u4ee5\u8bd5\u8bd5\u7b2c\u4e09\u65b9\u6a21\u5757\uff0c\u6bd4\u5982 pyautogui \u3002\u8fd8\u53ef\u4ee5\u8c03\u7528\u5927\u6f20\u63d2\u4ef6                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938283\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zictos \u914d\u7f6e\u597d\u7684\u7535\u8111\u53ea\u8fd0\u884c\u8fd9\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u76f8\u53cd\u914d\u7f6e\u5dee\u7684\u7535\u8111\u4e0a\u8fd0\u884c\u4e86\u5f88\u591a\u5a31\u4e50\u8f6f\u4ef6\u3002\u914d\u7f6e\u597d\u7684\u7535\u8111\u521a\u88c5\u7684\u3002pyautogui \u8fd9\u4e2a\u6bd4 win32api \u6162\u4e86\u592a\u591a\uff0c\u5df2\u7ecf\u653e\u5f03\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938284\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zictos \u5e76\u4e0d\u662f\u5076\u5c14\u4e00\u6b21\u4f1a\u8fd9\u6837\uff0c\u662f\u5c1d\u8bd5\u4e86\u591a\u6b21\u90fd\u662f\u8fd9\u6837\u7684\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938285\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zictos <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @cool1205 #2 \u7528 cython \u8f6c\u6210 C \u8bed\u8a00\u8bd5\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938286\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zictos \u6211\u5df2\u7ecf\u6709\u8fd9\u4e2a\u51b2\u52a8\u4e86\uff0c\u4e0d\u8fc7\u8fd8\u662f\u60f3\u518d\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u6362\u6210 C \u7684\u8bdd\uff0c\u4ee3\u7801\u90fd\u8981\u6362\uff0c\u5de5\u4f5c\u91cf\u6709\u4e9b\u5927                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938287\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mxT52CRuqR6o5 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e24\u53f0\u7535\u8111\u7cfb\u7edf\u4e00\u6837\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938288\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mxT52CRuqR6o5 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mxT52CRuqR6o5 \u90fd\u662f win10 \u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938289\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mxT52CRuqR6o5 \u90fd\u662f win 10\uff0c\u914d\u7f6e\u5dee\u7684\u4f01\u4e1a\u7248\uff0c\u914d\u7f6e\u597d\u7684\u4e13\u4e1a\u7248                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938290\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : thedrwu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u539f\u56e0\u592a\u591a\u4e86\u3002\u800c\u4e14\u8fd9 10ms \u7ea7\u7684\u8ddf\u786c\u4ef6\u672c\u8eab\u7684\u6027\u80fd\u5df2\u7ecf\u5173\u7cfb\u4e0d\u5927\u4e86\u3002<\/p>\n<p>\u5982\u679c\u9488\u5bf9\u7684\u662f\u7279\u5b9a app\uff0c\u76f4\u63a5\u53d1 wm_command \u6216\u8005 wm_char \u5427                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938291\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u627e\u5230\u4e86\u95ee\u9898\u6240\u5728\u4e86\uff0c\u6211\u5728\u6bcf\u6b21\u6267\u884c\u6a21\u62df\u9f20\u6807\u64cd\u4f5c\u524d\uff0c\u90fd\u6709\u6bb5\u5ef6\u65f6\uff0c\u6211\u5c06\u5ef6\u65f6\u4ee3\u7801\u53bb\u6389\u540e\uff0c\u914d\u7f6e\u597d\u7684\u7535\u8111\u6267\u884c 1ms \u90fd\u4e0d\u5230\uff0c\u76f8\u53cd\uff0c\u914d\u7f6e\u5dee\u7684\u7535\u8111\u50cf\u62bd\u98ce\u4e86\u4e00\u6837\uff0c\u65f6\u95f4\u51e0\u6beb\u79d2\u5230\u51e0\u5341\u6beb\u79d2\u3002\u867d\u7136\u4e0d\u77e5\u9053\u662f\u4ec0\u4e48\u539f\u56e0\u9020\u6210\u4e86\u8fd9\u6837\u4e00\u4e2a\u60c5\u51b5\uff0c\u4f46\u6548\u679c\u975e\u5e38\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938292\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u662f\u5982\u4f55\u5f97\u77e5\u51fd\u6570\u8fd0\u884c\u65f6\u95f4\u7684\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938293\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jeeyong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf7\u95ee\u914d\u7f6e\u597d\u7684\u7535\u8111\u662f\u4e0d\u662f\u90a3\u79cd\u591a\u6838, \u4f4e\u4e3b\u9891\u7684 cpu. \u5dee\u7684\u662f\u6838\u5fc3\u5c11, \u4f46\u662f\u4e3b\u9891\u9ad8\u4e8e\u597d\u7684\u673a\u5668\u8fd9\u79cd\u60c5\u51b5?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938294\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AX5N <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ahk \u4e0d\u9999\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938295\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jeeyong \u914d\u7f6e\u597d\u7684\u662f R7 5800x\uff0c\u914d\u7f6e\u5dee\u7684\u662f i5 9400F\uff0c\u5404\u65b9\u9762\u90fd\u662f R7 5800x \u5389\u5bb3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938296\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jeeyong <br \/>t4 = int(round(time.time() * 1000))<br \/># time.sleep(0.003)<br \/>win32api.keybd_event(0x74, 0, 0, 0)<br \/>t5 = int(round(time.time() * 1000))<br \/>win32api.keybd_event(0x74, 0, win32con.KEYEVENTF_KEYUP, 0)<br \/>t6 = int(round(time.time() * 1000))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938297\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bytesfold <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             windows \u6709\u4e2a\u65f6\u949f\u5468\u671f\uff0c\u5bfc\u81f4 time.sleep(0.001)\u8fd9\u79cd\u64cd\u4f5c\u662f\u65e0\u6cd5\u505a\u5230\u7684\uff01\u8fd9\u4e2a\u65f6\u95f4\u5c31\u662f 10ms \u5de6\u53f3\uff08\uff1f\uff09\uff0c\u6211\u89c9\u5f97\u4f60\u8fd9\u8ddf\u8fd9\u79cd\u60c5\u51b5\u6709\u5173                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938298\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bytesfold <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u4e2a\u7cbe\u786e\u5230\u4e07\u5206\u4e4b\u4e00\u79d2(\u81f3\u5c11)\u7684\u5b9a\u65f6\u5668\uff08\u867d\u7136\u5f88\u5360\u7528 cpu \uff09<\/p>\n<p>import time<br \/>import timeit<\/p>\n<p>def sleep(sleep_time):<br \/> target_time = time.perf_counter() + sleep_time<br \/> while time.perf_counter() &lt; target_time:<br \/> pass<\/p>\n<p>start = timeit.default_timer()<br \/>sleep(0.001)<br \/>print(&#8220;total used {} s.&#8221;.format(timeit.default_timer() &#8211; start))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938299\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cool1205 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bytesfold \u867d\u7136\u8fd9\u4e2a time.sleep()\u5e95\u5c42\u4e0e\u539f\u7406\u662f\u5982\u4f55\u5b9e\u73b0\u6211\u4e0d\u6e05\u695a\uff0c\u6211\u731c\u4e5f\u662f\u8fd9\u4e2a\u539f\u56e0\uff0c\u65e0\u6cd5\u5b9e\u73b0\u6beb\u79d2\u7ea7\u522b\u7684\u5ef6\u65f6\uff0c\u4ee5\u524d\u505a\u5d4c\u5165\u5f0f arm \u3001dsp \u57fa\u672c\u4e0a\u90fd\u662f\u62ff\u65f6\u949f\u9891\u7387\u6765\u7b97\u8fd0\u884c\u65f6\u95f4\uff0c\u53ef python \u8fd9\u79cd\u9ad8\u7ea7\u8bed\u8a00\u8fd8\u8ddf windows \u64cd\u4f5c\u7cfb\u7edf\u6709\u5173\uff0c\u6211\u5c31\u6709\u70b9\u513f\u4e0d\u61c2\u4e86\uff0c\u4e0d\u8fc7\u6548\u679c\u80fd\u591f\u8fbe\u5230\u5c31\u597d\u4e86\uff0c\u6bd5\u7adf\u8fd9\u4e2a\u9886\u57df\u4e0d\u4e13\u4e1a\uff0c\u80fd\u62ff\u6765\u7528\u5e76\u4e14 \u7a33\u5b9a\u5c31\u597d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4938300\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8d70 postmessage \u4e48\uff1f<br \/>\u53ea\u80fd\u8d70 keybd_event \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5728 windows &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/279997"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=279997"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/279997\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=279997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=279997"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=279997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}