GetText() public static method

public static GetText ( ) : string
return string
Example #1
0
 public static string GetClipBoardData()
 {
     try
     {
         string    ClipData  = null;
         Exception e         = null;
         Thread    staThread = new Thread(
             delegate()
         {
             try
             {
                 ClipData = Clipboard.GetText(TextDataFormat.Text);
             }
             catch (Exception ex)
             { e = ex; }
         });
         staThread.SetApartmentState(ApartmentState.STA);
         staThread.Start();
         staThread.Join();
         return(ClipData);
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
        /// <exception cref="System.Runtime.InteropServices.ExternalException"></exception>
        /// <exception cref="System.Threading.ThreadStateException"></exception>
        private void KeyboardMouseEvents_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if ((usingControl && e.Control == false) ||
                (!usingControl && e.Control == true))
            {
                return;
            }

            if ((usingShift && e.Shift == false) ||
                (!usingShift && e.Shift == true))
            {
                return;
            }

            if ((usingAlt && e.Alt == false) ||
                (!usingAlt && e.Alt == true))
            {
                return;
            }

            if (((char)e.KeyValue) == cbKeys.SelectedItem.ToString()[0])
            {
                if (Clipboard.ContainsText())
                {
                    string content = Clipboard.GetText();

                    content = selectedMockType.MockifyText(content);

                    Clipboard.SetText(content);
                }
            }
        }
Example #3
0
        public string Classify(string start)
        {
            string tempstring = string.Empty;
            var    id         = Process.GetProcesses()
                                ?.FirstOrDefault(pr => pr.MainWindowTitle.Contains(@"v2018")).Id;

            SetForegroundWindow(Process.GetProcessById(id.Value).MainWindowHandle);
            InputSimulator sim = new InputSimulator();

            sim.Keyboard.KeyPress(new VirtualKeyCode[] { VirtualKeyCode.F5 });
            //SendKeys.SendWait("{F5}");
            //IntPtr hWnd= Process.GetCurrentProcess().MainWindowHandle;
            //System.Windows.Window wnd = new System.Windows.Window();

            //ClipboardMonitor monitor = new ClipboardMonitor();



            while (start.Equals(Clipboard.GetText()))
            {
                Thread.Sleep(100);
            }
            tempstring = Clipboard.GetText();

            if (Replace(ref start, tempstring, out var replace))
            {
                return(replace);
            }

            return(replace);
        }
Example #4
0
 public void DumpWFClipboardTest()
 {
     TestContext.WriteLine($"ContainsAudio: {WFClipboard.ContainsAudio()}");
     TestContext.WriteLine($"ContainsData: {WFClipboard.ContainsData(DataFormats.StringFormat)}");
     TestContext.WriteLine($"ContainsFileDropList: {WFClipboard.ContainsFileDropList()}");
     TestContext.WriteLine($"ContainsImage: {WFClipboard.ContainsImage()}");
     TestContext.WriteLine($"ContainsText: {WFClipboard.ContainsText()}");
     TestContext.WriteLine($"GetAudioStream: {WFClipboard.GetAudioStream()}");
     TestContext.WriteLine($"GetData: {WFClipboard.GetData(DataFormats.StringFormat)}");
     TestContext.WriteLine($"GetDataObject: {WFClipboard.GetDataObject()}");
     TestContext.WriteLine($"GetFileDropList: {string.Join("\n", WFClipboard.GetFileDropList().Cast<string>())}");
     TestContext.WriteLine($"GetImage: {WFClipboard.GetImage()}");
     TestContext.WriteLine($"GetText: {WFClipboard.GetText()}");
 }
Example #5
0
        void _hook_OnMouseActivity(object sender, CustomMouseEventArgs e)
        {
            //Console.WriteLine(String.Format(">> {0}{1} - {2}{3}", e.Button, e.Clicks, DateTime.Now.ToString("HH:mm:ss"), Environment.NewLine));

            if (e.Button == MouseButton.Left)
            {
                Thread.Sleep(100);

                keybd_event((byte)Keys.ControlKey, 0, 0, 0); //模拟按下ctrl
                keybd_event((byte)Keys.C, 0, 0, 0);          //模拟按下c
                keybd_event((byte)Keys.ControlKey, 0, 2, 0); //模拟松开ctrl
                keybd_event((byte)Keys.C, 0, 2, 0);          //模拟松开c

                Thread.Sleep(100);

                SearchWord(Clipboard.GetText());
                //Clipboard.Clear();
            }
        }
Example #6
0
        /// <summary>
        /// 获取剪切板文本
        /// </summary>
        public static string GetClipboard()
        {
            string text = null;
            Thread th   = new Thread(new ThreadStart(delegate()
            {
                try
                {
                    text = Clipboard.GetText();
                }
                catch (Exception ex)
                {
                    LogUtil.Log(ex);
                }
            }));

            th.TrySetApartmentState(ApartmentState.STA);
            th.Start();
            th.Join();
            return(text);
        }
Example #7
0
 public static string GetText(TextDataFormat format)
 {
     return(ClipboardProxy.GetText(format));
 }
Example #8
0
 public static string GetText()
 {
     return(ClipboardProxy.GetText());
 }
Example #9
0
 public string GetText()
 {
     return(FormsClipboard.GetText());
 }
Example #10
0
 public void SaveClipboardToRecent()
 {
     Console.WriteLine("attempting to save clipboard to recent");
     if (!selfCopy)
     {
         Console.WriteLine("checking for recent duplicate");
         ClipboardObject duplicateObject = null;
         foreach (ClipboardObject clipboardObject in categories[0].ClipboardObjects)
         {
             if (clipboardObject.MatchesClipboard())
             {
                 duplicateObject = clipboardObject;
                 break;
             }
         }
         if (duplicateObject != null)
         {
             Console.WriteLine("moving duplicate clipboard to most recent");
             categories[0].RemoveClipboardObject(duplicateObject);
             if (CurrentCategoryId == categories[0].Id)
             {
                 ContentPanel.Children.Remove(duplicateObject.ClipboardContainer);
             }
             duplicateObject.Name = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
             categories[0].AddClipboardObject(duplicateObject);
             if (CurrentCategoryId == categories[0].Id)
             {
                 ContentPanel.Children.Insert(1, duplicateObject.ClipboardContainer);
             }
         }
         else
         {
             ClipboardObject newClipboardObject = null;
             Console.WriteLine("not a duplicate, finding format to save as");
             foreach (string format in Clipboard.GetDataObject().GetFormats())
             {
                 Console.WriteLine(format);
             }
             if (Clipboard.ContainsText())
             {
                 newClipboardObject = new TextClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetText());
             }
             else if (Clipboard.ContainsImage())
             {
                 newClipboardObject = new ImageClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetDataObject());
             }
             else if (Clipboard.ContainsFileDropList())
             {
                 newClipboardObject = new FileDropListClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetFileDropList());
             }
             if (newClipboardObject != null)
             {
                 categories[0].AddClipboardObject(newClipboardObject);
                 if (CurrentCategoryId == categories[0].Id)
                 {
                     ContentPanel.Children.Insert(1, newClipboardObject.ClipboardContainer);
                 }
                 if (categories[0].ClipboardObjects.Count() > MAX_RECENTS)
                 {
                     categories[0].RemoveClipboardObject(categories[0].ClipboardObjects.Last());
                     if (CurrentCategoryId == categories[0].Id)
                     {
                         ContentPanel.Children.RemoveAt(categories[0].ClipboardObjects.Count() + 1);
                     }
                 }
             }
         }
         SetActiveCategory(Recent.ID);
     }
     else
     {
         Console.WriteLine("ignoring self copy");
         selfCopy = false;
     }
 }
Example #11
0
 public void PasteAsText()
 {
     richTextBox1.SelectedText = Clipboard.GetText(); //粘贴纯文本
 }
Example #12
0
        static void Main(string[] args)
        {
            PathType pathType   = PathType.None;
            string   parsedPath = null;

            var        screenBounds = Screen.PrimaryScreen.Bounds;
            GImgClicks gimgClicks   = null;

            foreach (var supported in GImgClicksSupported)
            {
                if (supported.ScreenResolution.Width == screenBounds.Width && supported.ScreenResolution.Height == screenBounds.Height)
                {
                    gimgClicks = supported;
                    break;
                }
            }
            if (gimgClicks == null)
            {
                MessageBox.Show("Error: Screen resolution not supported.", "GoSearch");
                return;
            }

            Utility.RunAsSTAThread(() =>
            {
                if (Clipboard.ContainsText())
                {
                    var s = Clipboard.GetText();
                    if (s.StartsWith("http://") || s.StartsWith("https://"))
                    {
                        pathType = PathType.WebUrl;
                        return;
                    }
                    else if (File.Exists(s))
                    {
                        pathType = PathType.LocalFile;
                        return;
                    }
                }
                // Note The WPF version of Clipboard.GetImage() is buggy
                if (Clipboard.ContainsImage())
                {
                    var image  = Clipboard.GetImage();
                    parsedPath = Path.Combine(Path.GetTempPath(), "temp-gs.png");
                    pathType   = PathType.LocalFile;
                    image.Save(parsedPath, System.Drawing.Imaging.ImageFormat.Png);
                    return;
                }
                if (Clipboard.ContainsFileDropList())
                {
                    var fs     = Clipboard.GetFileDropList();
                    parsedPath = fs[0];
                    pathType   = PathType.LocalFile;
                }
            });

            if (pathType == PathType.None)
            {
                MessageBox.Show("Error: No valid path copied.", "GoSearch");
                return;
            }

            var w = new ControlledWindow
            {
                ProcessPath = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
                Arguments   = @"-inprivate http://images.google.com"
            };

            void SleepAndCheck(int sleepMs = 500)
            {
                Thread.Sleep(500);
                if (w.Process.HasExited)
                {
                    throw new TargetWindowExited();
                }
            }

            if (!w.CreateNew(x => x.StartsWith("Google Images")))
            {
                MessageBox.Show("Error: Failed to create new browser window.", "GoSearch");
                return;
            }
            try
            {
                if (!w.Process.HasExited && w.WindowRect.HasValue)
                {
                    if (!w.WaitUntilTitleStartsWith("Google Images"))
                    {
                        MessageBox.Show("Error: Failed to load Google Images site.", "GoSearch");
                        return;
                    }
                    if (w.Process.HasExited)
                    {
                        return;
                    }

                    //var bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                    //const int StandardResolutionWidth = 1920;
                    //const int StandardResolutionHeight = 1080;
                    //const int StandardClickX = 1200;
                    //const int StandardClickY = 550;
                    //if (bounds.Width == StandardResolutionHeight && bounds.Height  == StandardResolutionWidth)
                    //{
                    //    Input.MouseClick(1200, 550);
                    //}
                    //else
                    //{
                    //    var x = StandardClickX * bounds.Width / StandardResolutionWidth;
                    //    var y = StandardClickY * bounds.Height / StandardResolutionHeight;
                    //    Input.MouseClick(x, y);
                    //}
                    Input.MouseClick(gimgClicks.CameraButton.X, gimgClicks.CameraButton.Y);

                    SleepAndCheck();
                    if (w.Process.HasExited)
                    {
                        return;
                    }
                    if (pathType == PathType.WebUrl)
                    {
                        Debug.Assert(parsedPath == null);
                        CtrlV();
                    }
                    else if (pathType == PathType.LocalFile)
                    {
                        Input.MouseClick(gimgClicks.UploadImageTab.X, gimgClicks.UploadImageTab.Y);
                        SleepAndCheck();
                        Input.MouseClick(gimgClicks.ChooseFileButton.X, gimgClicks.ChooseFileButton.Y);
                        SleepAndCheck();
                        if (parsedPath != null)
                        {
                            Input.TypeStr("\"" + parsedPath + "\"\n");
                        }
                        else
                        {
                            CtrlV();
                        }
                    }
                }
            }
            catch (TargetWindowExited)
            {
                MessageBox.Show("Error: Search window lost.", "GoSearch");
            }
        }
Example #13
0
        void GetClipboardContents()
        {
            if (_image)
            {
                if (WinFormsClipboard.ContainsImage())
                {
                    _result = WinFormsClipboard.GetImage();
                }

                return;
            }

            if (_audio)
            {
                if (WinFormsClipboard.ContainsAudio())
                {
                    _result = WinFormsClipboard.GetAudioStream();
                }

                return;
            }

            if (_files)
            {
                if (WinFormsClipboard.ContainsFileDropList())
                {
                    StringCollection      paths = WinFormsClipboard.GetFileDropList();
                    List <FileSystemInfo> infos = new List <FileSystemInfo>();

                    foreach (string p in paths)
                    {
                        if (File.Exists(p))
                        {
                            infos.Add(new FileInfo(p));
                        }
                        else if (Directory.Exists(p))
                        {
                            infos.Add(new DirectoryInfo(p));
                        }
                    }

                    _result = infos.ToArray();
                }

                return;
            }

            if (_html)
            {
                if (WinFormsClipboard.ContainsText(TextDataFormat.Html))
                {
                    string       content      = WinFormsClipboard.GetText(TextDataFormat.Html);
                    RegexOptions regexOptions = RegexOptions.Singleline | RegexOptions.IgnoreCase;

                    if (_html && _htmlFragment)
                    {
                        Regex regex = new Regex("<!--StartFragment-->(.*)<!--EndFragment-->", regexOptions);
                        Match match = regex.Match(content);
                        if (match.Success)
                        {
                            content = match.Groups[1].Value;
                        }
                    }
                    else if (_html)
                    {
                        Regex regex = new Regex(".*?(<HTML>.*)", regexOptions);
                        Match match = regex.Match(content);
                        if (match.Success)
                        {
                            content = match.Groups[1].Value;
                        }
                    }

                    _result = content;
                    return;
                }

                return;
            }

            if (WinFormsClipboard.ContainsText())
            {
                _result = WinFormsClipboard.GetText(RequestedTextFormat);
                return;
            }
        }