Ejemplo n.º 1
0
        /// <summary>
        /// Add a new Window to the collection.  Intended for
        /// internal use by EnumWindows only.
        /// </summary>
        /// <param name="hWnd">Window handle to add</param>
        public void Add(IntPtr hWnd)
        {
            EnumWindowsItem item = new EnumWindowsItem(hWnd);

            this.InnerList.Add(item);
        }
Ejemplo n.º 2
0
            private void ApplyInputs(Func <string, string> environmentVariableLookup = null)
            {
                foreach (var input in Inputs)
                {
                    var    element = Element as AutomationElement;
                    object pattern = null;

                    try
                    {
                        switch (input.Type)
                        {
                        case WindowsAutomationMapping.Map.Input.InputTypes.Direction:
                            var hwnd = NativeWindowsHandle;
                            BreezyTrace.Log(TraceEventType.Verbose, String.Format("Sending direction key: {0} to hwnd: {1}", input.Value, hwnd));
                            var item = new EnumWindowsItem(hwnd, WindowsAutomation.TimeDilation);
                            switch (input.Value)
                            {
                            case "Up":
                                item.SendUp();
                                break;

                            case "Down":
                                item.SendDown();
                                break;

                            case "Left":
                                item.SendLeft();
                                break;

                            case "Right":
                                item.SendRight();
                                break;

                            default:
                                break;
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Esc:
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Invoke:
                            if (element.TryGetCurrentPattern(InvokePattern.Pattern, out pattern))
                            {
                                (pattern as InvokePattern).Invoke();
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.ExpandCollapse:
                            if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern))
                            {
                                element.SetFocus();
                                var expandCollapse = pattern as ExpandCollapsePattern;
                                if (
                                    (expandCollapse.Current.ExpandCollapseState.HasFlag(ExpandCollapseState.Collapsed) || expandCollapse.Current.ExpandCollapseState.HasFlag(ExpandCollapseState.PartiallyExpanded)) &&
                                    input.Value == "Expand"
                                    )
                                {
                                    expandCollapse.Expand();
                                }
                                else if (input.Value == "Collapse")
                                {
                                    expandCollapse.Collapse();
                                }
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.SendKey:
                            hwnd = NativeWindowsHandle;
                            item = new EnumWindowsItem(hwnd, WindowsAutomation.TimeDilation);
                            var b = Convert.ToByte(input.Value);
                            item.SendKey(b);
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Letter:
                            //hwnd = NativeWindowsHandle;
                            //item = new EnumWindowsItem(hwnd, WindowsAutomation.TimeDilation);
                            //item.SendKey(input.Value);
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Number:
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Return:
                            hwnd = NativeWindowsHandle;
                            BreezyTrace.Log(TraceEventType.Verbose, String.Format("Sending Enter key: {0} to hwnd: {1}", input.Value, hwnd));
                            item = new EnumWindowsItem(hwnd, WindowsAutomation.TimeDilation);
                            item.SendReturn();
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.SelectionItem:
                            if (element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern))
                            {
                                (pattern as SelectionItemPattern).Select();
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Selection:
                            //doesn't do anything
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Tab:
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Text:
                            //check to see if we're referencing an WF services environment variable (e.g. TempDir) and if so, get that value
                            var val = EnvironmentVariableSubstitution(input.Value, environmentVariableLookup);

                            if (element.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
                            {
                                (pattern as ValuePattern).SetValue(val);
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Toggle:
                            if (element.TryGetCurrentPattern(TogglePattern.Pattern, out pattern))
                            {
                                var toggle = pattern as TogglePattern;
                                if (
                                    (toggle.Current.ToggleState == ToggleState.Off && input.Value == "On") ||
                                    (toggle.Current.ToggleState == ToggleState.On && input.Value == "Off")
                                    )
                                {
                                    toggle.Toggle();
                                }
                            }
                            break;

                        case WindowsAutomationMapping.Map.Input.InputTypes.Wait:
                            var delay = Decimal.ToInt32(Convert.ToInt32(input.Value) * WindowsAutomation.TimeDilation);
                            Thread.Sleep(delay);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        BreezyTrace.Log(TraceEventType.Information, "Input failed for this mapping.", ex);
                    }

                    BreezyTrace.Log(TraceEventType.Verbose, String.Format("Successfully applied input type: {0}", input.Type));
                }
            }