{"id":6695,"date":"2021-12-18T11:53:47","date_gmt":"2021-12-18T11:53:47","guid":{"rendered":"https:\/\/blog.gwlin.com\/?p=6695"},"modified":"2023-04-02T10:48:59","modified_gmt":"2023-04-02T02:48:59","slug":"%e7%a8%8b%e5%ba%8f%e5%91%98%e7%9a%84%e6%84%a4%e6%80%92-%e7%94%a8python%e5%9c%a8%e3%80%8a%e6%9c%80%e7%bb%88%e5%b9%bb%e6%83%b310%e3%80%8b%e9%81%bf%e9%9b%b7200%e6%ac%a1","status":"publish","type":"post","link":"https:\/\/www.gwlin.com\/blog\/posts\/6695","title":{"rendered":"\u7a0b\u5e8f\u5458\u7684\u6124\u6012&#8211;\u7528python\u5728\u300a\u6700\u7ec8\u5e7b\u60f310\u300b\u907f\u96f7200\u6b21"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/blog.gwlin.com\/wp-content\/uploads\/2021\/12\/reconsidering-final-fantasys-awkward-middle-age-with-final-fantasy-x-hd.jpg\" alt=\"\" class=\"wp-image-42867\"\/><\/figure>\n\n\n\n<p>\u5728\u300a\u6700\u7ec8\u5e7b\u60f310\u300b\u4e2d\u6709\u4e00\u4e2a\u5c0f\u6e38\u620f\u9700\u8981\u8fde\u7eed\u8eb2\u907f\u95ea\u7535200\u6b21\u4ee5\u4e0a\uff0c\u672c\u6765\u5bf9\u6e38\u620f\u4e2d\u7684\u5c0f\u6e38\u620f\u4e0d\u600e\u4e48\u4e0a\u5fc3\u7684\uff0c\u65e0\u5948\u5956\u54c1\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6b66\u5668\u5347\u7ea7\u9053\u5177\uff0c\u53ea\u80fd\u786c\u7740\u5934\u76ae\u4e0a\u3002\u4f46\u624b\u6b8b\u52a0\u6ca1\u8010\u5fc3\u7684\u6211\u8bd5\u4e86\u51e0\u6b21\uff0c\u6700\u591a\u8fde\u7eed10\u6765\u6b21\u5c31\u65ad\u4e86\u3002\u770b\u4e86\u7f51\u4e0a\u8bf4\u8fde\u7eed200\u6b21\u9700\u8981\u534a\u4e2a\u5c0f\u65f6\u624d\u80fd\u641e\u5b9a\uff0c\u77ac\u95f4\u4e0d\u60f3\u73a9\u4e86\uff0c\u4f46\u53c8\u6709\u70b9\u4e0d\u7518\u5fc3\uff0c\u6709\u70b9\u751f\u6c14\uff0c\u611f\u89c9\u90fd\u662f\u6e38\u620f\u8bbe\u8ba1\u7684\u9519\u3002<\/p>\n\n\n\n<p>\u4ed4\u7ec6\u60f3\u4e86\u4e00\u4e0b\uff0c\u907f\u96f7\u7684\u4e00\u6574\u5957\u52a8\u4f5c\u90fd\u662f\u6709\u7279\u5f81\u548c\u56fa\u5b9a\u7684\uff0c\u4e0d\u8fc7\u662f\u8981\u91cd\u590d200\u6b21\u800c\u5df2\uff0c\u8fd9\u4e2a\u4e16\u754c\u4e0a\u6709\u4ec0\u4e48\u6bd4\u7a0b\u5e8f\u8fd8\u64c5\u957f\u505a\u91cd\u590d\u7684\u4efb\u52a1\u5462\uff1f\u8bf4\u5e72\u5c31\u5e72\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u95ea\u7535\u7684\u7279\u5f81\uff0c\u5168\u5c4f\u53d8\u767d\uff0c\u9a6c\u4e0a\u60f3\u5230\u80fd\u591f\u53d6\u6837\u51e0\u4e2a\u6e38\u620f\u7684\u50cf\u7d20\uff0c\u518d\u7528\u989c\u8272\u7a7a\u95f4\u7684\u8ddd\u79bb\u6765\u5224\u65ad\u51fa\u95ea\u7535\u7684\u65f6\u95f4\uff0c\u518d\u63a5\u4e0b\u6765\u6309\u4e0b\u8eb2\u907f\u952e\u5c31\u597d\u3002<\/p>\n\n\n\n<p>\u622a\u5c4f\u3001\u989c\u8272\u5904\u7406\u3001\u53d1\u9001\u6309\u952e\uff0c\u7528python\u3002\u4e8e\u662f\u5468\u516d\u65e9\u4e0a\u82b1\u4e86\u51e0\u4e2a\u5c0f\u65f6\u4e00\u8fb9\u627e\u8d44\u6599\uff0c\u4e00\u8fb9\u6d4b\uff0c\u5199\u4e86\u4e2a\u5c0f\u811a\u672c\uff0c\u4ee3\u7801\u6709\u70b9\u4e71\uff0c\u6ca1\u53bb\u6574\u7406\uff0c\u4e0d\u8fc7\u6548\u679c\u8fd8\u884c\u3002<\/p>\n\n\n\n<p>\u6253\u5f00\u6e38\u620f\uff0c\u8fdb\u5165\u843d\u96f7\u5e73\u539f\u540e\uff0c\u5207\u6362\u51fa\u6765\u8fd0\u884c\u811a\u672c\uff0c\u518d\u5207\u6362\u56de\u6e38\u620f\u3002\u5982\u679c\u6ca1\u95ee\u9898\u7684\u8bdd\uff0c\u9047\u5230\u95ea\u7535\u767d\u5c4f\u7684\u65f6\u5019\u5c31\u4f1a\u81ea\u52a8\u95ea\u907f\u3002\u6211\u662f\u5728\u7a97\u53e3\u6a21\u5f0f\u8fd0\u884c\u7684\uff0c\u5168\u5c4f\u4e0b\u6ca1\u8bd5\u8fc7\uff0c\u8bf7\u81ea\u884c\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import win32gui as win\nfrom PIL import ImageGrab\nimport signal\nimport sys\nimport colorsys\nfrom math import sin, cos\n\nfps = {}\n\nimport win32api, win32con, time\n\ndef pressKey(k):\n    win32api.keybd_event(k, win32api.MapVirtualKey(k, 0), 0, 0)\n    time.sleep(.2)\n    win32api.keybd_event(k, win32api.MapVirtualKey(k, 0), win32con.KEYEVENTF_KEYUP, 0)\n\ndef signal_handler(sig, frame):\n    print(fps)\n    sys.exit(0)\n\n\ndef fps_record():\n    t = int(time.time())\n    if t not in fps:\n        fps&#091;t] = 0\n    fps&#091;t] += 1\n\n\ndef hsv_distance(hsv1, hsv2):\n    h1, s1, v1 = hsv1\n    h2, s2, v2 = hsv2\n    return ((sin(h1) * s1 * v1 - sin(h2) * s2 * v2) ** 2) + ((cos(h1) * s1 * v1 - cos(h2) * s2 * v2) ** 2) + (\n                (v1 - v2) ** 2)\n\n\nif __name__ == &#039;__main__&#039;:\n    signal.signal(signal.SIGINT, signal_handler)\n    sampleNum = 10\n    striking=False\n    jump=0\n    while True:\n        forgroundwindow = win.GetForegroundWindow()\n        try:\n            bbox = win.GetWindowRect(forgroundwindow)\n        except:\n            time.sleep(0.5)\n            continue\n\n        img= ImageGrab.grab(bbox)\n        pixels = img.load()\n        height, width = img.size\n        height = int(height \/ 3)\n        width = int(width \/ 3)\n        sep = int(width \/ sampleNum)\n        samples = &#091;]\n        avgDistance = 0\n        for i in range(1, sampleNum):\n            hsv = colorsys.rgb_to_hsv(*pixels&#091;width + (i - 1) * sep, height])\n            samples.append(hsv)\n            avgDistance += hsv_distance((0, 0, 255), hsv)\n\n        avgDistance=avgDistance\/sampleNum\n        if avgDistance&lt;10000 and striking==False:\n            striking=True\n            time.sleep(0.1)\n            jump += 1\n            pressKey(0x43)\n            print(time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.gmtime()), &#039;\u95ea\u7535\uff1f +&#039;,jump)\n            time.sleep(0.2)\n        else:\n            striking=False\n\n        # fps_record()<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u662f\u8fd0\u884c\u622a\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.gwlin.com\/wp-content\/uploads\/2021\/12\/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211218125641.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.gwlin.com\/wp-content\/uploads\/2021\/12\/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211218125650.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u95ea\u907f200\u6b21\u7528\u4e8616\u5206\u949f\uff0c\u6bd4\u7f51\u4e0a\u8bf4\u7684\u5feb\u3002<\/p>\n\n\n\n<p>\u62ff\u5230\u5c0f\u6e38\u620f\u5956\u54c1\u540e\uff0c\u6709\u4e00\u79cd\u201c\u8001\u5b50\u679c\u7136\u5389\u5bb3\u201d\u7684\u611f\u89c9\uff0c\u4f46\u540c\u65f6\u4e5f\u6709\u4e00\u79cd\u83ab\u540d\u7684\u7a7a\u865a\u3002?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300a\u6700\u7ec8\u5e7b\u60f310\u300b\u4e2d\u6709\u4e00\u4e2a\u5c0f\u6e38\u620f\u9700\u8981\u8fde\u7eed\u8eb2\u907f\u95ea\u7535200\u6b21\u4ee5\u4e0a\uff0c\u672c\u6765\u5bf9\u6e38\u620f\u4e2d\u7684\u5c0f\u6e38\u620f\u4e0d\u600e\u4e48\u4e0a\u5fc3\u7684\uff0c\u65e0\u5948\u5956\u54c1\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6b66\u5668\u5347\u7ea7\u9053\u5177\uff0c\u53ea\u80fd\u786c\u7740\u5934\u76ae\u4e0a\u3002\u622a\u5c4f\u3001\u989c\u8272\u5904\u7406\u3001\u53d1\u9001\u6309\u952e\uff0c\u7528python\u3002\u4e8e\u662f\u5468\u516d\u65e9\u4e0a\u82b1\u4e86\u51e0\u4e2a\u5c0f\u65f6\u4e00\u8fb9\u627e\u8d44\u6599\uff0c\u4e00\u8fb9\u6d4b\uff0c\u5199\u4e86\u4e2a\u5c0f\u811a\u672c\uff0c\u4ee3\u7801\u6709\u70b9\u4e71\uff0c\u6ca1\u53bb\u6574\u7406\uff0c\u4e0d\u8fc7\u6548\u679c\u8fd8\u884c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[],"class_list":["post-6695","post","type-post","status-publish","format-standard","hentry","category-notes"],"_links":{"self":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/comments?post=6695"}],"version-history":[{"count":3,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6695\/revisions"}],"predecessor-version":[{"id":43148,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6695\/revisions\/43148"}],"wp:attachment":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/media?parent=6695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/categories?post=6695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/tags?post=6695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}