开发者

AutomationFocusChangedEventHandler does not always fire

开发者 https://www.devze.com 2023-04-01 15:54 出处:网络
I\'m working on a project in which I want my program to be notified when Internet Explorer gets focus or when navigating through tabs. To be clearer when an instance of IE gets focus or the user selec

I'm working on a project in which I want my program to be notified when Internet Explorer gets focus or when navigating through tabs. To be clearer when an instance of IE gets focus or the user selects another tab, I want my program to be notified.

To do this, I used AutomationFocusChangedEventHandler like this:

AutomationFocusChangedEventHandler focusHandler;

private void StartListening()
{
    focusHandler = new AutomationFocusChangedEventHandler(OnFocusChanged);
    Automation.AddAutomationFocusChangedEventHandler(focusHandler);
}

private void OnFocusChanged(object src, AutomationFocusChangedEventArgs e)
{
    AutomationElement ae = AutomationElement.FocusedElement;
    if (ae.Current.ClassName == "Internet Explorer_Server")
    {
        //do something here
    }
}

It works fine when I click on different instances of IEs, but when interacting with tabs, with some of these tabs, the onFocusChanged does not fi开发者_如何学JAVAre. With some tabs, It works fine but for others it does not (It does not detect tab changing for some tabs). Why? Am I missing something?

0

精彩评论

暂无评论...
验证码 换一张
取 消