目录
利用UIAutomation获取QQ会话聊天信息
效果
代码
AutomationElement window = AutomationElement.FromHandle(get.WindowHwnd);
AutomationElement QQMsgList = window.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "消息"));
if (QQMsgList != null)
{
AutomationElementCollection ALLMsg = QQMsgList.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
foreach (AutomationElement item in ALLMsg)
{
rtxtInfo.AppendText(item.Current.Name + "\r\n");
}
}
AutomationElement window = AutomationElement.FromHandle(get.WindowHwnd);
AutomationElement QQMsgList = window.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "消息"));
if (QQMsgList != null)
{
AutomationElementCollection ALLMsg = QQMsgList.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
foreach (AutomationElement item in ALLMsg)
{
rtxtInfo.AppendText(item.Current.Name + "\r\n");
}
}
目前遇到一个问题
获取的聊天信息不全,最近的多条聊天信息获取不到。
其他解决办法
1、截图OCR识别
2、不断复制,从剪切板中读取