コード例 #1
0
        public void Click()
        {
            if (AutomationElement.IsPatternSupported(InvokePattern.Pattern) && AutomationElement.Patterns.Invoke.TryGetPattern(out var invokePattern))
            {
                (invokePattern as InvokePattern)?.Invoke();
            }
            else if (AutomationElement.IsPatternSupported(SelectionItemPattern.Pattern) && AutomationElement.Patterns.SelectionItem.TryGetPattern(out var selectionPattern))
            {
                (selectionPattern as SelectionItemPattern)?.Select();
            }
            else if (AutomationElement.TryGetClickablePoint(out var pt))
            {
                var tempPos    = MouseWin32.GetPhysicalCursorPosition();
                var currentPos = new Point(tempPos.X, tempPos.Y);
                var targetPos  = new Point(pt.X, pt.Y);
                var mouseArgs  = MouseStr.ToMouseEventsArgs(targetPos.X, targetPos.Y, currentPos.X, currentPos.Y, "left", "press", 1);

                foreach (var arg in mouseArgs)
                {
                    MouseWin32.MouseEvent(arg.dwFlags, arg.dx, arg.dy, arg.dwData);
                    Thread.Sleep(10);
                }
            }
            else
            {
                throw new Exception($"Could not click element: {AutomationElement.Name}");
            }
        }
コード例 #2
0
        public void Click()
        {
            if (automationElement.TryGetClickablePoint(out var pt))
            {
                var tempPos    = MouseWin32.GetPhysicalCursorPosition();
                var currentPos = new Point(tempPos.X, tempPos.Y);
                var targetPos  = new Point((int)pt.X, (int)pt.Y);

                List <MouseStr.MouseEventArgs> mouseArgs =
                    MouseStr.ToMouseEventsArgs(
                        targetPos.X,
                        targetPos.Y,
                        currentPos.X,
                        currentPos.Y,
                        "left",
                        "press",
                        1);

                foreach (var arg in mouseArgs)
                {
                    MouseWin32.MouseEvent(arg.dwFlags, arg.dx, arg.dy, arg.dwData);
                    Thread.Sleep(10);
                }
            }
            else if (automationElement.TryGetCurrentPattern(InvokePattern.Pattern, out var invokePattern))
            {
                (invokePattern as InvokePattern)?.Invoke();
            }
            else if (automationElement.TryGetCurrentPattern(SelectionItemPattern.Pattern, out var selectionPattern))
            {
                (selectionPattern as SelectionItemPattern)?.Select();
            }
        }