代码修改自 微信弹幕消息 这个动作,目前已经可以实现获取类名ChatWnd下的最后一条消息。但是平时会有多个群,多个ChatWnd,想要改成获取指定窗口标题的最后一条消息。
//.cs 文件类型,便于外部编辑时使用
// 引用必要的命名空间
//css_dir C:\Windows\Microsoft.NET\assembly\GAC_MSIL\**
//css_ref UIAutomationClient.dll
using System.Collections.Generic;
using System.Windows.Automation;
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{ List <string> my_list = new List<string>();
AutomationElement root = AutomationElement.RootElement;
AutomationElement wx_win = root.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ChatWnd"));
AutomationElement msg_list = wx_win.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "消息"));
if (msg_list != null)
{
AutomationElementCollection all_msg = msg_list.FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
if (all_msg.Count > 0)
{
AutomationElement last_item = all_msg[all_msg.Count - 1];
AutomationElementCollection name = last_item.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
if (name.Count == 2)
{
if (last_item.Current.Name == "[地理位置]")
{
AutomationElementCollection text = last_item.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
my_list.Add(name[1].Current.Name + ":" + last_item.Current.Name + "\n" + text[0].Current.Name + "\n" + text[1].Current.Name);
}
else
{
my_list.Add(name[1].Current.Name + ":" + last_item.Current.Name);
}
}
else if (name.Count == 1)
{
my_list.Add(name[0].Current.Name + ":" + last_item.Current.Name);
}
}
}
context.SetVarValue("new_list", my_list); // 向变量里输出值
}
已自己解决