自动登陆QQ

import os
import time
import win32gui
import win32api
import win32con
from ctypes import *
from pykeyboard import PyKeyboard
from pymouse import PyMouse

# # 实例化PyKeyboard和PyMouse
m = PyMouse()
k = PyKeyboard()


def QQ_login():
    # 打开qq
    os.startfile(r"D:\Program Files\Tencent\QQ\Bin\QQScLauncher.exe")
    # 获取窗口的句柄
    time.sleep(2)
    # 获取窗口的句柄
    handle = win32gui.FindWindow(None, 'QQ')
    # 返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置354 a
    loginid = win32gui.GetWindowPlacement(handle)
    print(loginid, loginid[4][0])
    # 设置鼠标位置,横坐标等于左上角数加输入框离左边界的差值,纵坐标等于左上角数加输出狂上边界差值
    # 差值可用截图工具,测量像素差值
    windll.user32.SetCursorPos(loginid[4][0] + 280, loginid[4][1] + 250)
    # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    # time.sleep(12)
    # 模拟鼠标点击操作,左键按下再松开
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    time.sleep(0.1)
    k.type_string('QQ账号')
    time.sleep(1)
    # tab切换
    win32api.keybd_event(9, 0, 0, 0)
    win32api.keybd_event(9, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.1)
    k.type_string('QQ密码')
    time.sleep(1)
    # 点击回车键登陆
    win32api.keybd_event(13, 0, 0, 0)
    win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)

if __name__ == '__main__':
    while True:
        QQ_login()
        time.sleep(5)

  

posted @ 2019-07-16 14:27  不可描述的细节  阅读(191)  评论(0编辑  收藏  举报