''' 作者:夜雨喧嚣 时间:2021年8月12日 QQ:2012564991 ''' from uiautomation import * from time import sleep import random import win32gui as a import win32con as b import win32clipboard as c az = '歪比巴卜1' bb = [] while True : def fs(fsgs,fsnr) : c.OpenClipboard() c.EmptyClipboard() c.SetClipboardData(b.CF_UNICODETEXT, fsnr) c.CloseClipboard() handle = a.FindWindow(None, fsgs) if handle != 0: a.SendMessage(handle, 770, 0, 0) a.SendMessage(handle, b.WM_KEYDOWN, b.VK_RETURN, 0) print('发送成功!') abc = 0 aa = [] def print_all_childs_onebyone(farther, retract_level=0): abc = 0 def retract(retract_level): for i in range(retract_level): print("\t", end="") next_child = farther.GetFirstChildControl() retract(retract_level) try: print(next_child.Name) except: pass if next_child is not None: this_child_son = next_child.GetFirstChildControl() if this_child_son: print_all_childs_onebyone(next_child, retract_level + 1) while next_child: next_child = next_child.GetNextSiblingControl() retract(retract_level) try: print(next_child.Name) if ':' in next_child.Name : aa.append(next_child.Name) except : pass if next_child is not None: this_child_son = next_child.GetFirstChildControl() if this_child_son: print_all_childs_onebyone(next_child, retract_level + 1) chat_window = WindowControl(searchDepth=1, ClassName='TXGuiFoundation', Name='消息管理器') print(chat_window) sleep(1) print_all_childs_onebyone(chat_window, 1) print(aa) for i in range(1,4) : if aa[-i] in bb : break pp = aa[-i][aa[-i].index(':'):] print(10086,pp) if ('测试' in pp) and ('冬日暖阳' not in aa[-i]) : fs(az,'测试你个头') elif ('时间' in pp) and ('冬日暖阳' not in aa[-i]) : if ('开学' in pp) : fs(az,'新生大概9月16号吧,老生好像是9月7') else : print(aa[-1]) time.time() sj = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) fs(az,'尼玛问什么时间?不会自己去看?算了算了,现在时间是'+str(sj)) elif ('开学' in pp) and ('冬日暖阳' not in aa[-i]) : fs(az, '新生大概9月16号吧,老生好像是9月7') elif ('课' in pp) and ('多' in pp) and ('冬日暖阳' not in aa[-i]): fs(az,'学校课老多了') elif('食堂' in pp ) and ('冬日暖阳' not in aa[-i]) : if ('价格' in pp) or ('贵' in pp) : fs(az,'还好吧食堂价格,饭5毛或者6毛,素材基本上2到3块,荤菜3到5块,当然说的是金湖,早饭的肉包一个五毛,不过限购五个') elif('自习' in pp) and ('冬日暖阳' not in aa[-i]) : fs(az,'学校有早晚自习,大概是早上7点到7点半,晚上6点半到8点好像是奥,我忘记了,平时要自习可以去图书馆') elif('冬日暖阳' not in aa[-i]) : pass bb = aa import win32gui import win32api import win32con import time hwnd_title = dict() def _get_all_hwnd(hwnd, mouse): if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd): hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)}) win32gui.EnumWindows(_get_all_hwnd, 0) for wnd in hwnd_title.items(): print(wnd) if wnd[1] == '消息管理器': break long_position = win32api.MAKELONG(810, 130) win32api.SendMessage(int(wnd[0]), win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position) win32api.SendMessage(int(wnd[0]), win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)
记得单独打开要发送的窗口还有记得要打开消息管理器,因为是靠的遍历QQ消息管理器得到的聊天内容,B站发了一个叫《Python实现简易QQ机器人》的视频,里面有点讲解(当然我也不咋会编程讲解和没有一样),这个肯定比不过其他QQ机器人,只能说勉强可以用,给大家提供个思路。