Beispiel #1
0
        public bool Gestured(PointInfo actionPoint)
        {
            bool success = false;

            actionPoint.Invoke(() =>
            {
                IDataObject iData = Clipboard.GetDataObject();
                if (iData != null && iData.GetDataPresent(DataFormats.Text))
                {
                    string source = (string)iData.GetData(DataFormats.Text);
                    Regex reg     = new Regex(_matchString);
                    var match     = reg.Match(source);
                    if (match.Success)
                    {
                        string result = match.Value;
                        if (!string.IsNullOrWhiteSpace(result))
                        {
                            Clipboard.SetDataObject(result);
                            success = true;
                        }
                    }
                }
            });

            return(success);
        }
Beispiel #2
0
        public bool Gestured(PointInfo actionPoint)
        {
            Point             target            = _position == null ? new Point(actionPoint.PointLocation[0].X, actionPoint.PointLocation[0].Y) : _position.Value;
            AutomationElement targetTextElement = GetTargetTextElement(target);

            if (targetTextElement == null)
            {
                return(false);
            }

            string text = ExtractText(targetTextElement);

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            bool success = false;

            actionPoint.Invoke(() =>
            {
                Clipboard.SetText(text);
                Clipboard.Flush();
                success = true;
            });

            return(success);
        }
        public bool Gestured(PointInfo pointInfo)
        {
            if (_Settings == null)
            {
                return(false);
            }

            string clipboardString = string.Empty;

            using (Process process = new Process())
            {
                process.StartInfo.FileName        = "cmd.exe";
                process.StartInfo.Arguments       = $"{(_Settings.ShowCmd ? "/K " : "/C ")}\"{string.Join(" & ", _Settings.Command.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))}\"";
                process.StartInfo.WindowStyle     = _Settings.ShowCmd ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden;
                process.StartInfo.CreateNoWindow  = !_Settings.ShowCmd;
                process.StartInfo.UseShellExecute = false;

                process.StartInfo.EnvironmentVariables.Add("GS_StartPoint_X", pointInfo.PointLocation.First().X.ToString());
                process.StartInfo.EnvironmentVariables.Add("GS_StartPoint_Y", pointInfo.PointLocation.First().Y.ToString());
                process.StartInfo.EnvironmentVariables.Add("GS_EndPoint_X", pointInfo.Points[0].Last().X.ToString());
                process.StartInfo.EnvironmentVariables.Add("GS_EndPoint_Y", pointInfo.Points[0].Last().Y.ToString());
                process.StartInfo.EnvironmentVariables.Add("GS_Title", pointInfo.Window.Title);
                process.StartInfo.EnvironmentVariables.Add("GS_PID", pointInfo.Window.ProcessId.ToString());
                process.StartInfo.EnvironmentVariables.Add("GS_WindowHandle", pointInfo.WindowHandle.ToString());
                if (_Settings.Command.Contains("GS_ClassName"))
                {
                    process.StartInfo.EnvironmentVariables.Add("GS_ClassName", pointInfo.Window.ClassName);
                }
                if (_Settings.Command.Contains("GS_Clipboard"))
                {
                    pointInfo.Invoke(() =>
                    {
                        IDataObject iData = Clipboard.GetDataObject();
                        if (iData != null && iData.GetDataPresent(DataFormats.Text))
                        {
                            clipboardString = (string)iData.GetData(DataFormats.Text);
                        }
                    });
                    process.StartInfo.EnvironmentVariables.Add("GS_Clipboard", clipboardString);
                }
                process.Start();
            }

            return(true);
        }
Beispiel #4
0
        public string ExpandEnvironmentVariables(string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return(command);
            }

            command = Environment.ExpandEnvironmentVariables(command);

            if (command.Contains("%GS_Clipboard%"))
            {
                string clipboardString = string.Empty;
                _pointInfo.Invoke(() =>
                {
                    IDataObject iData = Clipboard.GetDataObject();
                    if (iData != null && iData.GetDataPresent(DataFormats.Text))
                    {
                        clipboardString = (string)iData.GetData(DataFormats.Text);
                    }
                });
                if (!string.IsNullOrEmpty(clipboardString))
                {
                    command = command.Replace("%GS_Clipboard%", clipboardString);
                }
            }

            if (command.Contains("%GS_ClassName%") && !string.IsNullOrEmpty(_pointInfo.Window.ClassName))
            {
                command = command.Replace("%GS_ClassName%", _pointInfo.Window.ClassName);
            }
            if (command.Contains("%GS_Title%") && !string.IsNullOrEmpty(_pointInfo.Window.Title))
            {
                command = command.Replace("%GS_Title%", _pointInfo.Window.Title);
            }
            if (command.Contains("%GS_PID%"))
            {
                command = command.Replace("%GS_PID%", _pointInfo.Window.ProcessId.ToString());
            }

            return(command.Replace("%GS_StartPoint_X%", _pointInfo.PointLocation.First().X.ToString()).
                   Replace("%GS_StartPoint_Y%", _pointInfo.PointLocation.First().Y.ToString()).
                   Replace("%GS_EndPoint_X%", _pointInfo.Points[0].Last().X.ToString()).
                   Replace("%GS_EndPoint_Y%", _pointInfo.Points[0].Last().Y.ToString()).
                   Replace("%GS_WindowHandle%", _pointInfo.WindowHandle.ToString()));
        }