0

I am using Windows.Automation framework to detect control having keyboard focus. So far I have tried the following :

private void M_GlobalHook_KeyDown(object sender, KeyEventArgs e)
    {
                var focusedElement = AutomationElement.FocusedElement;
                Console.WriteLine("Name : " + focusedElement.Current.Name);
                Console.WriteLine("AccessKey : " + focusedElement.Current.AccessKey);
                Console.WriteLine("ClassName : " + focusedElement.Current.ClassName);
                Console.WriteLine("IsControlElement : " + focusedElement.Current.IsControlElement);
                Console.WriteLine("ItemType : " + focusedElement.Current.ItemType);
                Console.WriteLine("IsPassword : " + focusedElement.Current.IsPassword);
}

I am getting incorrect control intermittently. It is fetching parent control for the target application (TrGUI.exe), instead of the textbox when I start typing immediately after launching.

I also tried to get the keyboard caret coordinates, so that I can use AutomationElement.FromPoint to get the desired control. But, I was not able to get those caret coordinates correctly.

1 Answers1

0

Found out there are two libraries available for AutomationElement. One is UIAComWrapper and other is UIAutomationClient + UIAutomationType.

If I implement using UIAComWrapper, I get the parent control instead of the child control that has keyboard focus. But if I implement using UIAutomationClient + UIAutomationType, I get the accurate control details.

Found comparison between two in this post.