How to detect that narrator tool is running?

坚强是说给别人听的谎言 提交于 2019-12-06 07:10:56

问题


I have a custom control. i like to provide the support for System screen reading support. Is there any logic to find that the narrator or coded UI tool is enabled in our machine.??


回答1:


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

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



回答2:


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.
}


来源:https://stackoverflow.com/questions/45275649/how-to-detect-that-narrator-tool-is-running

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