UIAUTOMATION 实现自动在群聊发「我要打中二节奏」
拿到 uiautomation 的第一次大胆尝试
我也不知道里面有没有 bug 就是了 (lll¬ω¬)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| import uiautomation as auto import time import random
QQ_Number = 20852085
RealOnlinestat = "在线状态:20"
GroupName = "2085 交流群"
GroupNumber = 208520852
InputList = [ "我要打中二节奏", "我好想打中二节奏", "坐上地铁", "三步两步飞到机厅" ] ListSize = InputList.__len__()
InputContent = InputList[random.randint(0, ListSize-1)] print(InputContent)
Group_Window = auto.PaneControl(searchDepth=1, Name = GroupName) taskbar = auto.PaneControl(searchDepth=1, Name = "任务栏") QQNum_string = str(QQ_Number)
Big_QQ = taskbar.ButtonControl(SubName = "QQ - ") flag = 1 if Big_QQ.Exists(2) == 0: flag = 0 if flag: Big_QQ.Click() if flag == 0: None elif " - 1 个 " in Big_QQ.Name: Group_Window = auto.PaneControl(Name = GroupName) elif flag: QQ_List = auto.ListControl(Name = "任务切换程序") Group_Button = QQ_List.ListItemControl(Name = GroupName) if Group_Button.Exists() == True: Group_Button.Click() Group_Window = auto.PaneControl(Name = GroupName) else: flag = 0
if flag == False:
Notification_Area = taskbar.ToolBarControl(Name = "用户提示通知区域")
Notifi_Children = Notification_Area.GetChildren()
Little_QQ_Exists = 0
for item in Notifi_Children: if QQNum_string in item.Name: item.Click() Little_QQ_Exists = 1 break if Little_QQ_Exists == 0: Apps = taskbar.PaneControl(searchDepth=1, Name = "DesktopWindowXamlSource") GetStarted = taskbar.ButtonControl(Name = "开始") GetStarted.Click() time.sleep(1) StartMenu = auto.WindowControl(searchDepth=1, Name = "开始") AllApps_Button = StartMenu.GetChildren()[1].ButtonControl(Name = "所有应用") AllApps_Button.Click() Apps_List = StartMenu.GetChildren()[1].GetChildren()[4].GetChildren()[0] First_Index = Apps_List.GetChildren()[0] First_Index.Click() ZoomApps = StartMenu.ListControl(Name = "缩小的所有应用") Q_Index = ZoomApps.ListItemControl(Name = "Q") Q_Index.Click() QQ_App = Apps_List.GroupControl(Name = "Q").ListItemControl(Name = "QQ") QQ_App.Click() time.sleep(7)
QQ_Main = auto.PaneControl(searchDepth=1, Name = "QQ") Online_Stat = QQ_Main.ButtonControl(Name = RealOnlinestat) if Online_Stat.Exists() == False: QQ_Prev = QQ_Main.GetPreviousSiblingControl() flag = 0 while QQ_Prev != None: if QQ_Prev.Name == "QQ": QQ_Main = QQ_Prev flag = 1 break QQ_Prev = QQ_Prev.GetPreviousSiblingControl() if flag == 0: QQ_Next = QQ_Main.GetNextSiblingControl() while QQ_Next != None: if QQ_Next.Name == "QQ": QQ_Main = QQ_Next break QQ_Next = QQ_Next.GetNextSiblingControl()
Search = QQ_Main.ComboBoxControl() Search.Click() In_Search = QQ_Main.ComboBoxControl() In_Search.SendKeys("{Ctrl}A") In_Search.SendKeys("{Back}") In_Search.SendKeys(GroupName)
GroupString = GroupName + " (" + str(GroupNumber) + ")" Genshin_Group = QQ_Main.ListItemControl(subname = str(GroupNumber)) Genshin_Group.Click()
Group_Window = auto.PaneControl(Name = GroupName)
Text_Editor = Group_Window.WindowControl(Name = "Rich Text Editor") InputBox = Text_Editor.EditControl() InputBox.Click() time.sleep(0.25) InputBox.SendKeys(InputContent)
NextGroup = Text_Editor.GetParentControl().GetNextSiblingControl() Send = NextGroup.ButtonControl(Name = "发送") Send.Click()
|