Last active
March 31, 2016 10:40
-
-
Save ambyte/05d104091fae119b46ebe56fcf77e779 to your computer and use it in GitHub Desktop.
Some code for Accessible and UIAutomation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Accessible GetFocused(Accessible objParent) | |
{ | |
Accessible objToReturn = default(Accessible); | |
if (objParent != null) | |
{ | |
Accessible[] children = null; | |
objParent.Children(out children); | |
if (children != null) | |
{ | |
foreach (var accessible in children) | |
{ | |
if (accessible != null) | |
{ | |
if ((accessible.State & 4) != 0) | |
{ | |
return accessible; | |
} | |
objToReturn = GetFocused(accessible); | |
if (objToReturn != default(Accessible)) | |
{ | |
return objToReturn; | |
} | |
} | |
} | |
} | |
} | |
return objToReturn; | |
} | |
private bool IsTextControl() | |
{ | |
try | |
{ | |
var element = AutomationElement.FocusedElement; | |
if (element != null) | |
{ | |
AutomationElement framework = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.HasKeyboardFocusProperty, true)); | |
if (framework != null) | |
{ | |
if (framework.GetCurrentPropertyValue(AutomationElement.IsTextPatternAvailableProperty) != null) | |
{ | |
return true; | |
} | |
if (framework.Current.ControlType.Equals(ControlType.Text) || framework.Current.ControlType.Equals(ControlType.Edit)) | |
{ | |
return true; | |
} | |
} | |
} | |
} | |
catch (Exception ex) { Trace.WriteLine(ex); } | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment