uia監(jiān)聽元素屬性,元素樹結(jié)構(gòu)變化

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

//訪問 .NET 類的靜態(tài)成員
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 = "會(huì)話",
        ControlType = "List";
    },wxwin) 
    console.log(items.Current.Name);
    /***
    // 注冊(cè)元素屬性變化事件監(jiān)聽
    Automation.Automation.AddAutomationEventHandler(
        Automation.AutomationElementIdentifiers.AutomationPropertyChangedEvent,
        items,
        TreeScope.Descendants, // 監(jiān)聽子元素變化
        function(element,e){
            ..console.log("3")
            ..console.dump("3",element.Current.LocalizedControlType,element.Current.Name,element.Current.Name,e.StructureChangeType);
        }
    );
    ***/
    
    // 注冊(cè)其他變化事件監(jiān)聽
    Automation.Automation.AddAutomationPropertyChangedEventHandler(
        items,
        TreeScope.Descendants, // 監(jiān)聽子元素變化
        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,      // 開關(guān)狀態(tài)
Automation.SelectionPattern.SelectionProperty,      // 選中項(xiàng)
}
    );
    
    
    // 注冊(cè)元素添加事件監(jiān)聽
    Automation.Automation.AddStructureChangedEventHandler(
        items,
        TreeScope.Descendants, // 監(jiān)聽子元素變化
        function(element,e){
            // 微信會(huì)話框只有增加、移除事件,沒有value、name變化事件
..console.dump("2",element.Current.LocalizedControlType,element.Current.Name,el
        }
    );
    
    
}


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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容