/// <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); } } catch { } return(null); }
/// <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); }