Skip to content

Instantly share code, notes, and snippets.

@ambyte
Last active March 31, 2016 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambyte/05d104091fae119b46ebe56fcf77e779 to your computer and use it in GitHub Desktop.
Save ambyte/05d104091fae119b46ebe56fcf77e779 to your computer and use it in GitHub Desktop.
Some code for Accessible and UIAutomation
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