예제 #1
0
        private void buttonInstall_Click(object sender, System.EventArgs e)
        {
            // EXAMPLE CODE SECTION

            AddText("Adding mouse hook.");
            mouseHook.InstallHook();

            AddText("Adding keyboard hook.");
            keyboardHook.InstallHook();

            buttonInstall.Enabled   = false;
            buttonUninstall.Enabled = true;
        }
예제 #2
0
        private void buttonInstall_Click(object sender, System.EventArgs e)
        {
            // EXAMPLE CODE SECTION

            process = Process.Start(srcPath);
            AutomationElement aeDeskTop = AutomationElement.RootElement;

            Thread.Sleep(500);
            //AutomationElement aeForm = null;
            int times = 0;

            process.WaitForInputIdle();
            while (process.MainWindowHandle == null || process.MainWindowHandle == IntPtr.Zero)
            {
                Thread.Sleep(1000);
                if (times > 5 && process.Handle != IntPtr.Zero)
                {
                    break;
                }
                times++;
            }
            if (process.MainWindowHandle == IntPtr.Zero)
            {
                EnumWindows(callBackEnumWindows, 0);
            }
            else
            {
                elementList.Add(AutomationElement.FromHandle(process.MainWindowHandle));
            }

            Condition condition1 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            Condition condition2 = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
            Condition condition  = new PropertyCondition(AutomationElement.ProcessIdProperty, process.Id);
            //AutomationElement aeForm = AutomationElement.FromHandle(process.MainWindowHandle);
            CacheRequest fetchRequest = new CacheRequest();

            fetchRequest.Add(AutomationElement.NameProperty);
            fetchRequest.Add(AutomationElement.AutomationIdProperty);
            fetchRequest.Add(AutomationElement.ControlTypeProperty);
            fetchRequest.Add(AutomationElement.BoundingRectangleProperty);

            using (fetchRequest.Activate())
            {
                foreach (AutomationElement aeForm in elementList)
                {
                    AutomationElementCollection tElemList = aeForm.FindAll(TreeScope.Subtree, new AndCondition(condition, condition1, condition2));
                    //elements = aeForm.FindAll(TreeScope.Subtree, new AndCondition(condition1, condition2, condition));
                    ///elements.CopyTo(temp, temp.Count);
                    for (int i = 0; i < tElemList.Count; i++)
                    {
                        childElemList.Add(tElemList[i]);
                    }
                }
                //WalkEnabledElements(aeDeskTop);
            }
            //fetchRequest.Add(AutomationElement.IsContentElementProperty);
            //foreach (AutomationElement element in elementList)
            //{
            //    WalkEnabledElements(element);
            //}

            //elements = aeDeskTop.FindAll(TreeScope.Subtree, new AndCondition(condition1, condition2, condition));

            AddText("Adding mouse hook.");
            mouseHook.InstallHook(this.Handle);

            AddText("Adding keyboard hook.");
            keyboardHook.InstallHook(this.Handle);

            AddText("Adding cbt hook");
            cbtHook.InstallHook(this.Handle);

            buttonInstall.Enabled   = false;
            buttonUninstall.Enabled = true;
        }