ddt-sharp-shoote
這是一個(gè)基于 Pynput 的 DDT 工具怪瓶′陶埃基本原理在于疼燥,得知風(fēng)力、角度珍语、距離的情況下,參考力度表得出發(fā)射力度,而后發(fā)射腌紧。 其中,風(fēng)力夜涕、角度通過(guò) ddddocr(An awesome captcha recognition library)識(shí)別颤专,屏距通過(guò)標(biāo)記屏距測(cè)量框、敵我位置來(lái)推算钠乏,力度通過(guò)按壓時(shí)長(zhǎng)來(lái)體現(xiàn)栖秕,具體見這里。
使用到的庫(kù):
screeninfo晓避、pillow簇捍、ddddocr、pynput
pynput: 控制和監(jiān)視輸入設(shè)備俏拱;類似的有PyHook3(監(jiān)視鍵鼠)暑塑、pywin32 (模擬鍵鼠)
ddddocr:識(shí)別驗(yàn)證碼,這邊用來(lái)識(shí)別數(shù)字
py2app: 將Python程序打包成MacOS應(yīng)用程序
新東西:
1.進(jìn)程間通信
Tkinter界面開啟mainloop進(jìn)程锅必,其中又開辟出一個(gè)子線程來(lái)偵聽其他進(jìn)程發(fā)送的數(shù)據(jù)消息事格,然后通過(guò)
tk.Text
控件來(lái)展示
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n17" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace; margin-top: 0px; margin-bottom: 20px; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background: rgb(51, 51, 51); position: relative !important; padding: 10px 10px 10px 30px; width: inherit; color: rgb(184, 191, 198); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">import multiprocessing
import threading
import time
import tkinter
聲明全局對(duì)象及類型
_tk: tkinter.Tk
_text: tkinter.Text
_terminate = False
_queue: multiprocessing.Queue
def update_text():
"""子線程偵聽進(jìn)程消息"""
while not _terminate:
if not _queue.empty():
text = _queue.get(False)
append_text(text)
else:
time.sleep(1)
def append_text(text):
_text.config(state='normal')
_text.insert('end', f'\n{text}')
_text.see('end')
_text.config(state='disabled')
def run(gui_queue):
global _tk, _text, _queue, _screen_size
_queue = gui_queue
...
threading.Thread(target=update_text).start()
_tk.mainloop()
</pre>
2.創(chuàng)建MacOS應(yīng)用
py2app setup
,在macos下創(chuàng)建python應(yīng)用搞隐, python setup.py py2app
3.識(shí)別數(shù)字并清晰
對(duì)純數(shù)字識(shí)別結(jié)果進(jìn)行清洗
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="python" cid="n22" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace; margin-top: 0px; margin-bottom: 20px; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background: rgb(51, 51, 51); position: relative !important; padding: 10px 10px 10px 30px; width: inherit; color: rgb(184, 191, 198); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">def recognize_digits(image: bytes):
ocr = ddddocr.DdddOcr(show_ad=False)
result = ocr.classification(image)
return wash_digits(result)
def wash_digits(digits: str):
"""由于不會(huì)出現(xiàn)非數(shù)字, 所以對(duì)易識(shí)別錯(cuò)誤的字符進(jìn)行替換"""
washed = digits
.replace('g', '9').replace('q', '9')
.replace('l', '1').replace('i', '1')
.replace('z', '2')
.replace('o', '0')
return re.sub(r'\D', '0', washed)</pre>