コード例 #1
0
        private void OnMessage(NativeMessagingMessage message)
        {
            try
            {
                //lock(_lock)
                //{

                //    //if (dpiscale == 0)
                //    //{
                //    //    dpiscale = NativeMethods.getScalingFactor();
                //    //} else
                //    //{
                //    //    dpiscale = NativeMethods.getScalingFactor();
                //    //}
                //    var dpi = NativeMethods.GetDpiForSystem();
                //    dpiscale = 1;
                //    if (dpi == 96) dpiscale = 1;
                //    if (dpi == 120) dpiscale = 1.25f;
                //    if (dpi == 144) dpiscale = 1.5f;
                //    if (dpi == 192) dpiscale = 2;
                //}
                if (message.uiy > 0 && message.uix > 0 && message.uiwidth > 0 && message.uiheight > 0)
                {
                    //message.uiy = (int)(message.uiy * dpiscale);
                    //message.uix = (int)(message.uix * dpiscale);
                    //message.uiwidth = (int)(message.uiwidth * dpiscale);
                    //message.uiheight = (int)(message.uiheight * dpiscale);
                    if (dpiscale == 1.25)
                    {
                        message.uiy += 158;
                    }
                    LastElement = new NMElement(message);
                }

                if (message.functionName == "click")
                {
                    if (IsRecording)
                    {
                        if (LastElement == null)
                        {
                            return;
                        }
                        var re = new RecordEvent
                        {
                            Button = Input.MouseButton.Left
                        }; var a = new GetElement {
                            DisplayName = LastElement.ToString()
                        };
                        a.Variables.Add(new Variable <int>("Index", 0));
                        a.Variables.Add(new Variable <int>("Total", 0));

                        message.tab = NMHook.FindTabById(message.browser, message.tabid);

                        var selector = new NMSelector(LastElement, null, true, null);
                        a.Selector   = selector.ToString();
                        a.Image      = LastElement.ImageString();
                        a.MaxResults = 1;

                        re.Selector      = selector;
                        re.a             = new GetElementResult(a);
                        re.SupportInput  = LastElement.SupportInput;
                        re.SupportSelect = false;
                        re.ClickHandled  = true;
                        OnUserAction?.Invoke(this, re);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
コード例 #2
0
ファイル: Plugin.cs プロジェクト: mahiz/openrpa
        public bool ParseUserAction(ref IRecordEvent e)
        {
            if (e.UIElement == null)
            {
                return(false);
            }

            if (e.UIElement.ProcessId < 1)
            {
                return(false);
            }
            var p = System.Diagnostics.Process.GetProcessById(e.UIElement.ProcessId);

            if (p.ProcessName.ToLower() != "chrome" && p.ProcessName.ToLower() != "firefox" && p.ProcessName.ToLower() != "msedge")
            {
                return(false);
            }

            if (p.ProcessName.ToLower() == "chrome" && !NMHook.chromeconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Chrome, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (p.ProcessName.ToLower() == "msedge" && !NMHook.edgeconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Edge, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (p.ProcessName.ToLower() == "firefox" && !NMHook.ffconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Firefix, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (LastElement == null)
            {
                return(false);
            }
            if (LastElement.message == null)
            {
                return(false);
            }
            if (LastElement.message.tab == null)
            {
                LastElement.message.tab = NMHook.tabs.Where(x => x.id == LastElement.message.tabid && x.browser == LastElement.message.browser && x.windowId == LastElement.message.windowId).FirstOrDefault();
            }
            if (p.ProcessName.ToLower() == "chrome" || p.ProcessName.ToLower() == "msedge")
            {
                if (e.UIElement.FrameworkId != "chrome" && e.UIElement.FrameworkId != "Chrome")
                {
                    return(false);
                }
            }
            var selector = new NMSelector(LastElement, null, true, null);
            var a        = new GetElement {
                DisplayName = LastElement.id + " " + LastElement.type + " " + LastElement.Name
            };

            a.Selector   = selector.ToString();
            a.Image      = LastElement.ImageString();
            a.MaxResults = 1;

            e.Element       = LastElement;
            e.Selector      = selector;
            e.a             = new GetElementResult(a);
            e.SupportInput  = LastElement.SupportInput;
            e.SupportSelect = LastElement.tagname.ToLower() == "select";
            e.OffsetX       = e.X - LastElement.Rectangle.X;
            e.OffsetY       = e.Y - LastElement.Rectangle.Y;
            e.ClickHandled  = false;
            //e.ClickHandled = true;
            //LastElement.Click(true, e.Button, e.X, e.Y, false, false);
            return(true);
        }