예제 #1
1
        public bool checkHandle()
        {
            Guid guid = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
            object obj = null;
            int retVal = AccessibleObjectFromWindow(handle, (uint)OBJID.WINDOW, ref guid, ref obj);
            iAccessible = (IAccessible)obj;

            //The AccWindowName returned is Add-ons Manager - Mozilla Firefox
            //There is a special child id called CHILDID_SELF (this constant equals 0) that, when used with a function like get_accChild, returns the element itself rather than a child.

            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal = iAccessible.get_accValue(0);

            Console.WriteLine("IAccessible Name : " + accWindowName);
            Console.WriteLine("IAccessible value : " + accWindowVal);
            Console.WriteLine("IAccessible Role is : " + iAccessible.get_accRole(0));

            Console.WriteLine("IAccessible Type: " + iAccessible.GetType());
            Console.WriteLine("IAccessible Focus is: " + iAccessible.accFocus);
            Console.WriteLine("IAccessible Selection is " + iAccessible.get_accState());
            //iAccessible.accSelect((int)OBJID.SELFLAG_TAKEFOCUS, 0);
            if (!accWindowName.Contains("Mozilla Firefox"))
                return false;

            getChild(iAccessible,false);

            //End of for window
            Console.WriteLine("End of checkHandle");
            iAccessible = null;
            return false;
        }
예제 #2
0
        /// <summary>
        /// Given a control, generates the complete path that the script language uses to identify it.
        /// This is reliably useful only if all parents have meaningful and sufficiently unique names.
        /// </summary>
        /// <param name="cLeaf"></param>
        /// <returns></returns>
        public static string AccessPath(Control cLeaf)
        {
            StringBuilder sb = new StringBuilder();

            // Build the string from the back, as a sequence of role:name pairs separated by /
            for (Control c = cLeaf; c != null; c = c.Parent)
            {
                if (sb.Length != 0)
                {
                    sb.Insert(0, "/");
                }
                System.Reflection.PropertyInfo pi = c.GetType().GetProperty("AccessibleRootObject");
                if (pi == null)
                {
                    AccessibleObject ao = c.AccessibilityObject;
                    sb.Insert(0, ao.Name);
                    sb.Insert(0, ":");
                    sb.Insert(0, ao.Role);
                }
                else
                {
                    IAccessible acc = (IAccessible)pi.GetValue(c, new object[0]);
                    sb.Insert(0, acc.get_accName(null));
                    sb.Insert(0, ":");
                    sb.Insert(0, InterpretRole(acc.get_accRole(null)));
                }
            }
            return(sb.ToString());
        }
예제 #3
0
        public bool checkHandle()
        {
            Guid   guid   = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
            object obj    = null;
            int    retVal = AccessibleObjectFromWindow(handle, (uint)OBJID.WINDOW, ref guid, ref obj);

            iAccessible = (IAccessible)obj;

            //The AccWindowName returned is Add-ons Manager - Mozilla Firefox
            //There is a special child id called CHILDID_SELF (this constant equals 0) that, when used with a function like get_accChild, returns the element itself rather than a child.

            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal  = iAccessible.get_accValue(0);

            Console.WriteLine("IAccessible Name : " + accWindowName);
            Console.WriteLine("IAccessible value : " + accWindowVal);
            Console.WriteLine("IAccessible Role is : " + iAccessible.get_accRole(0));

            Console.WriteLine("IAccessible Type: " + iAccessible.GetType());
            Console.WriteLine("IAccessible Focus is: " + iAccessible.accFocus);
            Console.WriteLine("IAccessible Selection is " + iAccessible.get_accState());
            //iAccessible.accSelect((int)OBJID.SELFLAG_TAKEFOCUS, 0);
            if (!accWindowName.Contains("Mozilla Firefox"))
            {
                return(false);
            }

            getChild(iAccessible, false);

            //End of for window
            Console.WriteLine("End of checkHandle");
            iAccessible = null;
            return(false);
        }
예제 #4
0
        public static IAccessible GetAccessibleObjectByNameAndRole(IAccessible iaccWindow, string accName, AccRole accRole)
        {
            IAccessible objReturn  = default(IAccessible);
            int         childCount = iaccWindow.accChildCount;

            object[] windowChildren = new object[childCount];
            int      pcObtained;
            int      result = AccessibleChildren(iaccWindow, 0, childCount, windowChildren, out pcObtained);
            string   name   = "";
            int      role;

            for (int i = 0; i < windowChildren.Count(); i++)
            {
                if (windowChildren[i].GetType() != typeof(int) && windowChildren[i].GetType() != typeof(string))
                {
                    IAccessible child = windowChildren[i] as IAccessible;
                    role = (int)child.get_accRole(CHILDID_SELF);
                    name = child.get_accName(CHILDID_SELF);
                    if (accName.Equals(name, StringComparison.CurrentCultureIgnoreCase) && role == accRole.GetHashCode())
                    {
                        return(child);
                    }
                    objReturn = GetAccessibleObjectByNameAndRole(child, accName, accRole);
                    if (objReturn != default(IAccessible))
                    {
                        return(objReturn);
                    }
                }
            }
            return(objReturn);
        }
예제 #5
0
        private void root_MouseDown(object sender, MouseEventArgs e)
        {
            Control          c           = sender as Control;
            AccessibleObject ao          = c.AccessibilityObject;
            Point            screenPoint = c.PointToScreen(new Point(e.X, e.Y));
            StringBuilder    sb          = new StringBuilder();

            System.Reflection.PropertyInfo pi = c.GetType().GetProperty("AccessibleRootObject");
            if (pi == null)
            {
                AccessibleObject aoPrev = null;                 // Some HitTests keep returning the leaf object.
                for (AccessibleObject aoCur = ao.HitTest(screenPoint.X, screenPoint.Y);
                     aoCur != null && aoCur != ao && aoCur != aoPrev;
                     aoCur = aoCur.HitTest(screenPoint.X, screenPoint.Y))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("/");
                    }
                    sb.Append(aoCur.Role);
                    sb.Append(":");
                    sb.Append(aoCur.Name);
                    aoPrev = aoCur;
                }
            }
            else
            {
                IAccessible acc = (IAccessible)pi.GetValue(c, new object[0]);

                for (IAccessible accCurr = (IAccessible)acc.accHitTest(screenPoint.X, screenPoint.Y);
                     accCurr != null;
                     accCurr = accCurr.accHitTest(screenPoint.X, screenPoint.Y) as IAccessible)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("/");
                    }
                    sb.Append(InterpretRole(accCurr.get_accRole(null)));
                    sb.Append(":");
                    sb.Append(accCurr.get_accName(null));
                }
            }

            string leafPath = sb.ToString();

            m_output.WriteStartElement("click");
            m_output.WriteAttributeString("path", AccessPath(sender as Control));
            m_output.WriteAttributeString("at", "(" + e.X + "," + e.Y + ")");
            if (leafPath.Length > 0)
            {
                m_output.WriteAttributeString("child", leafPath);
            }
            m_output.WriteEndElement();
            m_output.WriteWhitespace("\n");
            m_output.Flush();
        }
예제 #6
0
        public void UpdateRole()
        {
            object role = IAccessible.get_accRole(ChildId);

            if (!(role is int))
            {
                throw new VariantNotIntException(role);
            }

            Role = (int)role;
        }
예제 #7
0
        private void SetAccessibleProperties()
        {
            //Here we are consuming the COM Exceptions which happens in case
            //the property/Method we need is not available with IAccessible Object.

            try
            {
                _name = _accessible.get_accName(0);
            }
            catch (Exception ex)
            {
            }

            try
            {
                _value = _accessible.get_accValue(0);
            }
            catch (Exception ex)
            {
            }

            try
            {
                uint stateId = Convert.ToUInt32(_accessible.get_accState(0));
                _state = MSAA.GetStateText(stateId);
            }
            catch (Exception ex)
            {
            }

            try
            {
                uint roleId = Convert.ToUInt32(_accessible.get_accRole(0));
                _role = MSAA.GetRoleText(roleId);
            }
            catch (Exception ex)
            {
            }


            _handle = MSAA.GetHandle(_accessible);

            try
            {
                _defaultAction = _accessible.get_accDefaultAction(0);
            }
            catch (Exception ex)
            {
            }

            SetLocation(_accessible);
        }
예제 #8
0
        /// <summary>
        /// Retreive the role from the UI element
        /// </summary>
        /// <param name="pacc">object representing the UI element</param>
        /// <param name="roleID">role of window containing the UI element</param>
        /// <param name="roleRef">reference to accessibility role result</param>
        /// <returns>the element role as a string</returns>
        public static string GetUIElementRole(IAccessible pacc, int roleID, ref uint roleRef)
        {
            if (null == pacc)
            {
                return(string.Empty);
            }

            StringBuilder roleBuffer = new StringBuilder(256);
            object        o          = pacc.get_accRole(roleID);

            roleRef = Convert.ToUInt32(o, CultureInfo.InvariantCulture);

            if (roleRef >= 0)
            {
                NativeMethods.GetRoleText(roleRef, roleBuffer, (uint)roleBuffer.Capacity);
            }

            return(roleBuffer.ToString());
        }
예제 #9
0
        public void IAccessibleInterop()
        {
            // Get the clock
            AutomationElement taskbar = AutomationElement.RootElement.FindFirst(TreeScope.TreeScope_Children,
                                                                                new PropertyCondition(AutomationElement.ClassNameProperty, "Shell_TrayWnd"));

            Assert.IsNotNull(taskbar);

            AutomationElement clock = taskbar.FindFirst(TreeScope.TreeScope_Subtree,
                                                        new PropertyCondition(AutomationElement.ClassNameProperty, "TrayClockWClass"));

            Assert.IsNotNull(clock);

            // Get the IAccessible for the clock
            IntPtr clockHwnd     = (IntPtr)clock.Current.NativeWindowHandle;
            Guid   iidAccessible = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
            object obj           = null;
            int    retVal        = AccessibleObjectFromWindow(clockHwnd, (uint)0xFFFFFFFC, ref iidAccessible, ref obj);

            Assert.IsNotNull(obj);
            IAccessible accessible = (IAccessible)obj;

            Assert.IsNotNull(accessible);
            Assert.AreEqual(43 /* clock */, accessible.get_accRole(0));

            // Convert to an element
            AutomationElement element = AutomationElement.FromIAccessible(accessible, 0);

            Assert.IsNotNull(element);
            Assert.AreEqual(ControlType.Button, element.Current.ControlType);

            // Round-trip: let's get the IAccessible back out
            LegacyIAccessiblePattern legacy = (LegacyIAccessiblePattern)element.GetCurrentPattern(LegacyIAccessiblePattern.Pattern);
            IAccessible legacyIAcc          = legacy.GetIAccessible();

            Assert.IsNotNull(legacyIAcc);
            Assert.AreEqual(43 /* clock */, legacyIAcc.get_accRole(0));
        }
예제 #10
0
        internal static int GetRoleId(IAccessible accObj, int childId)
        {
            object obj2 = -1;

            try
            {
                obj2 = accObj.get_accRole(childId);
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception exception)
            {
                if (!IsOleAccException(exception) || !IsOleAccExceptionMaskable(exception))
                {
                    throw;
                }
            }
            if (obj2 is int)
            {
                return((int)obj2);
            }
            return(10);
        }
예제 #11
0
 object?IAccessibleInternal.get_accRole(object childID)
 => publicIAccessible.get_accRole(childID);
예제 #12
0
        internal static AccessibleRole GetRole(IAccessible acc, int idChild)
        {
            AccessibleRole rval;
            try
            {
                object role = acc.get_accRole(idChild);

                // get_accRole can return a non-int! for example, Outlook 2003 SUPERGRID entries
                // can return the string "Table View". so we return an int if we got one otherwise
                // we convert it to the generic "client" role.
                rval = (role is int) ? (AccessibleRole)(int)role : AccessibleRole.Client;
            }
            catch (Exception e)
            {
                if (HandleIAccessibleException(e))
                {
                    throw;
                }
                rval = AccessibleRole.Client;
            }
            return rval;
        }
 object UnsafeNativeMethods.IAccessibleInternal.get_accRole(object childID)
 {
     IntSecurity.UnmanagedCode.Assert();
     return(publicIAccessible.get_accRole(childID));
 }