uia监听元素属性,元素树结构变化

import System.Windows.Automation;
import web.json;
import win;
import console;
import win;

//访问 .NET 类的静态成员
Automation = System.Windows.Automation;
PropertyCondition = Automation.PropertyCondition;
AutomationElement = Automation.AutomationElement;
TreeScope = Automation.TreeScope; 

//查找窗口。由 System.Windows.Automation.And 生成查询条件。
var wxwin = Automation.FindByAnd({
    ClassName = "WeChatMainWndForPC",
    ControlType = "Window";
}) 

if(wxwin){
    var items = Automation.FindByAnd({
        Name = "会话",
        ControlType = "List";
    },wxwin) 
    console.log(items.Current.Name);
    /***
    // 注册元素属性变化事件监听
    Automation.Automation.AddAutomationEventHandler(
        Automation.AutomationElementIdentifiers.AutomationPropertyChangedEvent,
        items,
        TreeScope.Descendants, // 监听子元素变化
        function(element,e){
            ..console.log("3")
            ..console.dump("3",element.Current.LocalizedControlType,element.Current.Name,element.Current.Name,e.StructureChangeType);
        }
    );
    ***/
    
    // 注册其他变化事件监听
    Automation.Automation.AddAutomationPropertyChangedEventHandler(
        items,
        TreeScope.Descendants, // 监听子元素变化
        function(element,e){
          // 这里要用Inspect.exe查看is开头的属性是否激活了事件,否则白搭
            ..console.dump("1",element.Current.Name,e.Property.ProgrammaticName,e.NewValue);
                
        },{AutomationElement.NameProperty,          // 元素名称
AutomationElement.BoundingRectangleProperty, // 位置尺寸
Automation.ValuePattern.ValueProperty,              // 输入值
Automation.TogglePattern.ToggleStateProperty,      // 开关状态
Automation.SelectionPattern.SelectionProperty,      // 选中项
}
    );
    
    
    // 注册元素添加事件监听
    Automation.Automation.AddStructureChangedEventHandler(
        items,
        TreeScope.Descendants, // 监听子元素变化
        function(element,e){
            // 微信会话框只有增加、移除事件,没有value、name变化事件
..console.dump("2",element.Current.LocalizedControlType,element.Current.Name,el
        }
    );
    
    
}


win.loopMessage();
Automation.RemoveAllEventHandlers(); 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。