def input_ocr(self):
ocr = self.get_ocr_hwnd()
i = 0
while ocr>0 and i < 10:
self.capture_window(ocr, 'ocr.png')
code = pytesseract.image_to_string(Image.open('ocr.png')).strip('\n')
ctrl = ctypes.windll.user32.GetWindow(ocr, win32con.GW_HWNDNEXT)
ctrl = ctypes.windll.user32.GetWindow(ctrl, win32con.GW_HWNDNEXT)
ctrl = ctypes.windll.user32.GetWindow(ctrl, win32con.GW_HWNDNEXT)
set_text(ctrl, code)
hot_key(['enter'])
# with open('ocr.png', 'rb') as f:
# data = f.read()
# code = DdddOcr.classification(data)
# ctrl = ctypes.windll.user32.GetWindow(ocr, win32con.GW_HWNDNEXT)
# ctrl = ctypes.windll.user32.GetWindow(ctrl, win32con.GW_HWNDNEXT)
# ctrl = ctypes.windll.user32.GetWindow(ctrl, win32con.GW_HWNDNEXT)
# set_text(ctrl, code)
# hot_key(['enter'])
i += 1
err_text = get_text(ctypes.windll.user32.GetWindow(ocr, win32con.GW_HWNDNEXT))
if u'验证码错误' in err_text:
left, top, right, bottom = win32gui.GetWindowRect(ocr)
win32api.SetCursorPos(((left + right) // 2, (top + bottom) // 2))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
time.sleep(sleep_time)
else:
return