Ejemplo n.º 1
0
        public void TestClick(FlaUI.Core.Shapes.Point p)
        {
            var currClickPosition = Position;

            AutomationElementPropertyValues properties = appWindow.Properties;
            double leftPoisition = properties.BoundingRectangle.Value.Left;
            double topPoisition  = properties.BoundingRectangle.Value.Top;

            p.X += leftPoisition < 0 ? 0 : leftPoisition;
            p.Y += topPoisition < 0 ? 0 : topPoisition;

            p.X = p.X * 1.25;
            p.Y = p.Y * 1.25;

            Position = p;

            if (LastClickPositions.Count > 0 && LastClickPositions[MouseButton.Left].Equals(currClickPosition))
            {
                // Get the timeout needed to not fire a double click
                var timeout = (int)User32.GetDoubleClickTime() - DateTime.Now.Subtract(LastClickTimes[MouseButton.Left]).Milliseconds;
                // Wait the needed time to prevent the double click
                if (timeout > 0)
                {
                    Thread.Sleep(timeout);
                }
            }

            MouseButton mouseButton = MouseButton.Left;

            Down(mouseButton, p);
            Up(mouseButton, p);

            LastClickTimes[mouseButton]     = DateTime.Now;
            LastClickPositions[mouseButton] = Position;
        }
Ejemplo n.º 2
0
        public static void Up(MouseButton mouseButton, FlaUI.Core.Shapes.Point p)
        {
            uint data;
            var  flags = GetFlagsAndDataForButton(mouseButton, false, out data);

            SendInput((int)p.X, (int)p.Y, data, flags);
        }
Ejemplo n.º 3
0
        public void RunCurrent(string path)
        {
            string[] steps = path.Contains('\n') ? path.Split('\n') : new[] { path };
            JToken   obj   = null;

            foreach (string step in steps)
            {
                string[] parseStep = step.Trim().Split(".".ToCharArray());
                obj = objectDetails;
                foreach (string level in parseStep)
                {
                    obj = obj[level];
                }

                IEnumerable <JProperty> props = obj.ToObject <JObject>().Properties();
                JProperty properties          = props.Where(prop => prop.Name.ToString() == "_properties").First();
                JObject   propObj             = (JObject)JsonConvert.DeserializeObject(properties.Value.ToString());
                JObject   coordObj            = (JObject)JsonConvert.DeserializeObject(propObj["coordinates"].ToString());

                int x = (int)coordObj["x"];
                int y = (int)coordObj["y"];

                FlaUI.Core.Shapes.Point p = new FlaUI.Core.Shapes.Point((double)x, (double)y);
                int id = (int)propObj["id"];
                TestClick(p);
            }
        }
Ejemplo n.º 4
0
        public void SaveElementAttributes(string appName, string menu, string menuItem, AutomationElement menuItemObj, string Item, int id, AutomationElement itemObj)
        {
            appName  = appName.Replace(" ", "_").Replace(".", "");
            menu     = menu.Replace(" ", "_").Replace(".", "");
            menuItem = menuItem.ToString().Replace(" ", "").Replace(".", "").Trim();
            Item     = Item.ToString().Replace(" ", "").Replace(".", "").Trim();
            string controlType = "";

            double X = 0, Y = 0;

            if (menuItemObj != null)
            {
                FlaUI.Core.Shapes.Point menuP = menuItemObj.Properties.ClickablePoint;
                X           = menuP.X;
                Y           = menuP.Y;
                controlType = menuItemObj.ControlType.ToString();
            }

            double Xi = 0, Yi = 0;

            if (itemObj != null)
            {
                FlaUI.Core.Shapes.Point itemP = itemObj.Properties.ClickablePoint;
                Xi          = itemP.X;
                Yi          = itemP.Y;
                controlType = itemObj.ControlType.ToString();
            }

            JObject temp  = new JObject();
            Utils   utils = new Utils();

            if (!objectDetails.Any())
            {
                objectDetails[appName]                 = temp;
                objectDetails[appName][menu]           = temp;
                objectDetails[appName][menu][menuItem] = new JObject();
                objectDetails[appName][menu][menuItem]["_properties"] = utils.WriteProperties(--id, X, Y, menuItem, controlType);
                LocatedObjects.objectsDB.Add(id, menuItemObj);

                objectDetails[appName][menu][menuItem][Item] = new JObject();
                objectDetails[appName][menu][menuItem][Item]["_properties"] = utils.WriteProperties(++id, Xi, Yi, Item, controlType);
                LocatedObjects.objectsDB.Add(id, itemObj);
            }
            else if (objectDetails[appName][menu][menuItem] == null)
            {
                objectDetails[appName][menu][menuItem] = temp;
                objectDetails[appName][menu][menuItem]["_properties"] = utils.WriteProperties(--id, X, Y, menuItem, controlType);
                LocatedObjects.objectsDB.Add(id, menuItemObj);

                objectDetails[appName][menu][menuItem][Item] = temp;
                objectDetails[appName][menu][menuItem][Item]["_properties"] = utils.WriteProperties(++id, Xi, Yi, Item, controlType);
                LocatedObjects.objectsDB.Add(id, itemObj);
            }
            else if (objectDetails[appName][menu][menuItem][Item] == null)
            {
                objectDetails[appName][menu][menuItem][Item] = temp;
                objectDetails[appName][menu][menuItem][Item]["_properties"] = utils.WriteProperties(id, Xi, Yi, Item, controlType);
                LocatedObjects.objectsDB.Add(id, itemObj);
            }
        }
Ejemplo n.º 5
0
        void PrintElement()
        {
            //var automation = new UIA3Automation();
            FlaUI.Core.Shapes.Point pt1 = FlaUI.Core.Input.Mouse.Position;
            AutomationElement       e1  = automation.FromPoint(pt1);

            if (e1.Properties.ProcessId == Process.GetCurrentProcess().Id)
            {
                return;
            }

            e1.DrawHighlight(true, System.Windows.Media.Colors.Blue, TimeSpan.FromSeconds(1));

            //textBox1.Text = Process.GetProcessById(e.Properties.ProcessId).ProcessName + "(" + e.Properties.ProcessId + ")" + Environment.NewLine;
            //PrintElementHierarchy(e);
            textBox1.Text += FormatXPath(GetXPath(e1)) + Environment.NewLine;

            //if (true)
            //{
            //    FlaUI.Core.Shapes.Point pt1 = FlaUI.Core.Input.Mouse.Position;
            //    AutomationElement e = automation.FromPoint(pt1);
            //    e.DrawHighlight(true, System.Windows.Media.Colors.Blue, TimeSpan.FromSeconds(1));
            //}
            //else
            //{
            //    //AutomationElement e = automation.FromPoint(pt);
            //    //e.DrawHighlight(true, System.Windows.Media.Colors.Blue, TimeSpan.FromSeconds(1));
            //    //if (e.Properties.ProcessId == Process.GetCurrentProcess().Id)
            //    //    return;
            //    //textBox1.Text = Process.GetProcessById(e.Properties.ProcessId).ProcessName + "(" + e.Properties.ProcessId + ")" + Environment.NewLine;
            //    //PrintElementHierarchy(e);
            //}
        }
Ejemplo n.º 6
0
        public bool parseUserAction(ref IRecordEvent e)
        {
            if (e.UIElement == null)
            {
                return(false);
            }

            if (e.UIElement.Type != "Pane")
            {
                return(false);
            }
            var element = e.UIElement.RawElement;

            var p           = System.Diagnostics.Process.GetProcessById(e.UIElement.ProcessId);
            var Processname = p.ProcessName;

            FlaUI.Core.Shapes.Point point = new FlaUI.Core.Shapes.Point(e.X - 80, e.Y - 80);
            if (point.X < 0)
            {
                point.X = e.X + 80;
            }
            if (point.Y < 0)
            {
                point.Y = e.Y + 80;
            }
            FlaUI.Core.Input.Mouse.MoveTo(point);

            var a = new GetElement();

            a.Threshold    = 0.9;
            a.Processname  = Processname;
            e.SupportInput = false;
            int newOffsetX; int newOffsetY; System.Drawing.Rectangle resultrect;
            var image = getrectangle.GuessContour(element, e.OffsetX, e.OffsetY, out newOffsetX, out newOffsetY, out resultrect);

            if (image == null)
            {
                var tip = new Interfaces.Overlay.TooltipWindow("Failed Guessing Contour, please select manually");
                tip.SetTimeout(TimeSpan.FromSeconds(2));
                e.OffsetX = 10;
                e.OffsetY = 10;
                e.a       = new GetElementResult(a);
                return(true);
            }
            e.OffsetX = newOffsetX;
            e.OffsetY = newOffsetY;
            e.Element = new ImageElement(resultrect, image);

            a.Image = Interfaces.Image.Util.Bitmap2Base64(image);
            e.a     = new GetElementResult(a);

            point.X = e.X; point.Y = e.Y;
            FlaUI.Core.Input.Mouse.MoveTo(point);

            return(true);
        }
Ejemplo n.º 7
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                FlaUI.Core.Shapes.Point pt1 = FlaUI.Core.Input.Mouse.Position;
                AutomationElement       e1  = automation.FromPoint(pt1);
                if (e1.Properties.ProcessId == Process.GetCurrentProcess().Id)
                {
                    return;
                }

                e1.DrawHighlight(false, System.Windows.Media.Colors.Blue, TimeSpan.FromMilliseconds(500));
                if (e1 != LastElement)
                {
                    LastElement = e1;
                    LastXPath   = GetXPath(e1);
                    LastRect    = e1.BoundingRectangle;
                }
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 8
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            FlaUI.Core.Shapes.Point pt1 = FlaUI.Core.Input.Mouse.Position;
            AutomationElement       e1;

            try
            {
                e1 = automation.FromPoint(pt1);
            }
            catch (FileNotFoundException)
            {
                return;
            }
            //AutomationElement e1 = automation.FromPoint(pt1);
            if (e1.Properties.ProcessId == Process.GetCurrentProcess().Id)
            {
                return;
            }

            e1.DrawHighlight(false, System.Windows.Media.Colors.Blue, TimeSpan.FromSeconds(1.4));


            //MessageBox.Show("hi");
        }