public AutomationElement FromKeyboardFocus()
        {
            IUIAutomationElement pElement;

            pAutomation.GetFocusedElement(out pElement);
            return(pElement == null ? null : new AutomationElement(pElement, this));
        }
        public static AutomationElement FromKeyboardFocus()
        {
            IUIAutomationElement elem;

            pAutomation.GetFocusedElement(out elem);
            return((elem == null) ? null : new AutomationElement(elem));
        }
Example #3
0
 public AutomationElement FromKeyboardFocus()
 {
     try {
         IUIAutomationElement pElement;
         pAutomation.GetFocusedElement(out pElement);
         return(pElement == null ? null : new AutomationElement(pElement, this));
     }
     catch (COMException) {
         return(null);
     }
 }
Example #4
0
        /// <summary>
        /// Get the focused Element
        /// </summary>
        /// <returns></returns>
        public static DesktopElement GetFocusedElement()
        {
            try
            {
                var uia = UIAutomation.GetFocusedElement();

                if (!DesktopElement.IsFromCurrentProcess(uia))
                {
                    return(new DesktopElement(uia, true));
                }
                else
                {
                    Marshal.ReleaseComObject(uia);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(null);
        }