コード例 #1
0
        private void MouseClickAll(object sender, MouseEventArgs e)
        {
            POINT p;

            if (GetCursorPos(out p) && clickCheck == 0)
            {
                ScreenElement structure             = ScreenElement.fromAutomationElement(ElementFromCursor());
                long          currTime              = new StartTime().getStartTime();
                long          timeSinceStartSession = currTime - startTime;
                if (double.IsInfinity(structure.x) || double.IsInfinity(structure.y))
                {
                    using (Graphics g = Graphics.FromImage(pictureBox1.Image))
                    {
                        g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, 4, 4);
                    }
                    System.IO.File.AppendAllText(@"C:\Saif\Office\C#\Projects\MouseClick\file\" + startTime.ToString() + ".json", "\n{\"eventType\": \"md\"" + ", \"mouseX\": " + p.X + ", \"mouseY\": " + p.Y + ", \"elementX\": " + structureInCondition.x + ", \"elementY\": " + structureInCondition.y + ", \"elementW\": " + structureInCondition.width + ", \"elementH\": " + structureInCondition.height + ", \"time\": " + timeSinceStartSession + ", \"relative\": true" + "}");
                }
                else
                {
                    using (Graphics g = Graphics.FromImage(pictureBox1.Image))
                    {
                        g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, 4, 4);
                    }
                    System.IO.File.AppendAllText(@"C:\Saif\Office\C#\Projects\MouseClick\file\" + startTime.ToString() + ".json", "\n{\"eventType\": \"mc\"" + ", \"mouseX\": " + p.X + ", \"mouseY\": " + p.Y + ", \"elementX\": " + structure.x + ", \"elementY\": " + structure.y + ", \"elementW\": " + structure.width + ", \"elementH\": " + structure.height + ", \"time\": " + timeSinceStartSession + ", \"relative\": true" + "}");
                }
            }
        }
コード例 #2
0
            public static ScreenElement fromAutomationElement(AutomationElement element, CacheRequest cacheRequest = null)
            {
                if (element == null)
                {
                    return(null);
                }

                try
                {
                    bool cacheRequestMine = cacheRequest == null;
                    if (cacheRequestMine)
                    {
                        cacheRequest = new CacheRequest();
                        cacheRequest.Add(AutomationElement.ClassNameProperty);
                        cacheRequest.Add(AutomationElement.ControlTypeProperty);
                        cacheRequest.Add(AutomationElement.AutomationIdProperty);
                        cacheRequest.Add(AutomationElement.IsControlElementProperty);
                        cacheRequest.Add(AutomationElement.BoundingRectangleProperty);
                        cacheRequest.AutomationElementMode = AutomationElementMode.Full;
                        cacheRequest.TreeFilter            = Automation.RawViewCondition;
                        cacheRequest.Push();
                        element = element.GetUpdatedCache(cacheRequest);
                    }

                    var           p = element.Cached;
                    var           b = p.BoundingRectangle;
                    ScreenElement parent;
                    try
                    {
                        parent = ScreenElement.fromAutomationElement(TreeWalker.RawViewWalker.GetParent(element, cacheRequest), cacheRequest);
                    }
                    catch (Exception)
                    {
                        parent = null;
                    }
                    var r = new ScreenElement()
                    {
                        classname = p.ClassName,
                        type      = p.ControlType.ProgrammaticName,
                        id        = p.AutomationId,
                        isControl = p.IsControlElement,
                        x         = b.X,
                        y         = b.Y,
                        width     = b.Width,
                        height    = b.Height,
                        // parent = parent,
                    };
                    if (cacheRequestMine)
                    {
                        cacheRequest.Pop();
                    }
                    return(r);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
コード例 #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.DarkGray;

            Hook.GlobalEvents().MouseClick     += MouseClickAll;
            long          currTime              = new StartTime().getStartTime();
            long          timeSinceStartSession = currTime - startTime;
            ScreenElement structure             = ScreenElement.fromAutomationElement(ElementFromCursor());

            System.IO.File.AppendAllText(@"C:\Saif\Office\C#\Projects\MouseClick\file\" + startTime.ToString() + ".json", "{\"eventType\": \"mm\"" + ", \"mouseX\": " + Cursor.Position.X + ", \"mouseY\": " + Cursor.Position.Y + ", \"time\": " + timeSinceStartSession + ", \"relative\": true" + "}");
        }
コード例 #4
0
        private void timer_Tick(object sender, EventArgs e)
        {
            Thread th = new Thread(firstClick);

            th.Start();
            //firstClick();
            ScreenElement structure = ScreenElement.fromAutomationElement(ElementFromCursor());

            structureInCondition = structure;
            long currTime = new StartTime().getStartTime();
            long timeSinceStartSession = currTime - startTime;

            System.IO.File.AppendAllText(@"C:\Saif\Office\C#\Projects\MouseClick\file\" + startTime.ToString() + ".json", "\n{\"eventType\": \"mm\"" + ", \"mouseX\": " + Cursor.Position.X + ", \"mouseY\": " + Cursor.Position.Y + ", \"time\": " + timeSinceStartSession + ", \"relative\": true" + "}");
        }