python 自动登录电脑QQ 非坐标版

废话不多说,因为精力原因没有继续注释,如果大家有什么不懂得可以一起探讨一下

import win32gui, win32con, win32api, time, os
from pykeyboard import PyKeyboard
#QQ路径
QQpath = '"E:\Program Files\Tencent\QQ\Bin\QQScLauncher.exe"'

def run_qq(zh, mm):
    # 启动QQ
    os.system(QQpath)
    lstime = time.time()
    while 1:
        ls_hwnd = win32gui.GetForegroundWindow()
        if win32gui.GetWindowText(ls_hwnd) == 'QQ' and win32gui.GetClassName(ls_hwnd) == 'TXGuiFoundation':
            print(2, time.time() - lstime)
            break

    time.sleep(1)
    # win32gui.SetForegroundWindow(ls_hwnd)
    win32api.keybd_event(16, 0, 0, 0)
    # time.sleep(0.1)
    win32api.keybd_event(9, 0, 0, 0)
    win32api.keybd_event(9, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.1)
    win32api.keybd_event(16, 0, win32con.KEYEVENTF_KEYUP, 0)

    time.sleep(0.5)
    into = PyKeyboard()

    for i in zh:
        into.type_string(i)
        time.sleep(0.02)

    time.sleep(0.1)
    win32api.keybd_event(9, 0, 0, 0)
    win32api.keybd_event(9, 0, win32con.KEYEVENTF_KEYUP, 0)
    for i in mm:
        into.type_string(i)
        time.sleep(0.02)
    time.sleep(0.2)

    win32api.keybd_event(9, 0, 0, 0)
    win32api.keybd_event(9, 0, win32con.KEYEVENTF_KEYUP, 0)
    
    return ls_hwnd

zh = '2345678'
mm = '23456789'
print(run_qq(zh, mm))

代码

猜你喜欢

转载自blog.csdn.net/weixin_43304988/article/details/106875018