admin
2024-02-21 d1f88af76d8cb3b3751f53a1814081f2c5e997d1
utils/ths_util.py
@@ -1,5 +1,6 @@
import time
# 获取同花顺副屏幕1句柄
import win32api
import win32con
import win32_util
@@ -85,5 +86,72 @@
        time.sleep(space_time)
# 将代码加入自选
def input_code(hwnd, num_str):
    for c in num_str:
        code = -1
        if c == '0':
            code = 48
        elif c == '1':
            code = 49
        elif c == '2':
            code = 50
        elif c == '3':
            code = 51
        elif c == '4':
            code = 52
        elif c == '5':
            code = 53
        elif c == '6':
            code = 54
        elif c == '7':
            code = 55
        elif c == '8':
            code = 56
        elif c == '9':
            code = 57
        win32gui.SendMessage(hwnd, win32con.WM_KEYDOWN, code, 0)
        win32gui.PostMessage(hwnd, win32con.WM_KEYUP, code, 0)
        time.sleep(0.1)
def add_code_to_zixuan(num_str):
    hwnds = win32_util.search_window("看盘页面")
    if hwnds:
        origin_hwnd = hwnds[0]
        for w in hwnds:
            title = win32_util.getText(w)
            if title.find("同花顺")>=0:
                origin_hwnd = w
                break
        input_code(origin_hwnd, num_str[:1])
        # Afx:00400000:0
        hwnds = []
        try:
            hwnd = win32gui.GetDesktopWindow()
            temp = None
            while True:
                if temp and win32gui.IsWindowVisible(temp):
                    classname = win32gui.GetClassName(temp)
                    if classname == 'Afx:00400000:0':
                        hwnds.append(temp)
                temp = win32gui.FindWindowEx(hwnd, temp, None, None)
                if not temp:
                    break
        except:
            pass
        hwnd = win32gui.FindWindowEx(hwnds[0], None, "Edit", "")
        print(hwnd)
        input_code(hwnd, num_str[1:])
        time.sleep(0.5)
        win32gui.SendMessage(hwnds[0], win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
        win32gui.PostMessage(hwnds[0], win32con.WM_KEYUP, win32con.VK_RETURN, 0)
        time.sleep(0.2)
        win32gui.SetForegroundWindow(origin_hwnd)
        win32api.keybd_event(win32con.VK_INSERT, 0, 0, 0)  # 按下键
        win32api.keybd_event(win32con.VK_INSERT, 0, win32con.KEYEVENTF_KEYUP, 0)
if __name__ == "__main__":
    print(get_ths_main_content_hwnd())