UIAUTOMATION 实现自动在群聊发「我要打中二节奏」

11490DX Re: Master Lv.15

拿到 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
# FileName: Send_I_Want_To_Play_Chunithm_To_Genshin_Group.py
import uiautomation as auto
import time
import random

# 自定义参数:
# QQ 号
QQ_Number = 20852085
# 可以区分大、小号的大号在线状态
RealOnlinestat = "在线状态:20"
# 群名称
GroupName = "2085 交流群"
# 群号
GroupNumber = 208520852

# 欲输入的列表,内容里面随
InputList = [
"我要打中二节奏",
"我好想打中二节奏",
"坐上地铁",
"三步两步飞到机厅"
]
ListSize = InputList.__len__()

# 欲输入的内容
# InputContent = "I REALLY WANT TO PLAY CHUNITHM!"
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:

# 获取小 QQ 同时判断小 QQ 是否存在
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
# 若小 QQ 不存在,则可尝试点击大 QQ 图标使得本 QQ 号的 QQ 出现
# 同时需要判断是否存在小号的情况
if Little_QQ_Exists == 0:
Apps = taskbar.PaneControl(searchDepth=1, Name = "DesktopWindowXamlSource")
# 去 Windows 开始界面重新查找 QQ
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()
# 然后就跳到 Q 索引
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()
  • Title: UIAUTOMATION 实现自动在群聊发「我要打中二节奏」
  • Author: 11490DX
  • Created at : 2025-07-08 15:49:36
  • Updated at : 2025-07-28 08:02:38
  • Link: https://11490dx.net/2025/07/08/uiautomation-program/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
UIAUTOMATION 实现自动在群聊发「我要打中二节奏」