How to detect that narrator tool is running?

不羁岁月 提交于 2019-12-04 13:15:16

You can use namespace Windows.UI.Xaml.Automation.Peers and this method:

var isNarratorStarted = AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged);

I had similiar case but when working with UWP app and I solved it that way. Maybe you can take something from here:

private bool isAutomationPeerCreated = false;

private bool IsAutomationPeerAttached => this.isAutomationPeerCreated || AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged);

//triggered everytime you run narrator or any other screen reading software that is based on accessing automation properties
protected override AutomationPeer OnCreateAutomationPeer()
{
    if(!this.IsAutomationPeerAttached)
    {
        this.isAutomationPeerCreated = true;
        this.OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR();
    }
    return null;
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    base.OnNavigatedFrom(e);
    this.isAutomationPeerCreated = false;
}

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    if(IsAutomationPeerAttached)
    {
        this.OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR();       
    }
}

private void OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR()
{
    //DO STH.
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!