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.??
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.
}
来源:https://stackoverflow.com/questions/45275649/how-to-detect-that-narrator-tool-is-running