Exemplo n.º 1
0
        /// <summary>
        /// Uses the clipboard to try and retrieve selected text from the active control.
        /// </summary>
        /// <returns>
        /// Returns the selected text from the active control or null when the Clipboard method
        /// fails to retrieve the text.
        /// </returns>
        private string GetTextViaClipboard()
        {
            try
            {
                // Backup clipboard text.
                string clipboardText = Clipboard.GetText();

                // "CTRL+C" needs to be sent from a Single Threaded Apartment State thread.
                if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
                {
                    var thread = new Thread(() =>
                    {
                        SendKeys.SendWait("^c");
                        SendKeys.Flush();
                    });

                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
                else
                {
                    SendKeys.SendWait("^c");
                    SendKeys.Flush();
                }

                // Get clipboard text.
                string result = Clipboard.GetText();
                result = string.IsNullOrWhiteSpace(result) ? null : result;

                Clipboard.SetText(clipboardText);

                if (clipboardText == result)
                {
                    return(string.Empty);
                }
                else
                {
                    return(result);
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Exemplo n.º 2
0
        public static void SimulateSendKeys(this string keys)
        {
            //模拟发送+、^、%、~及圆括号 ( ) ,要将它放在大括号 ({}) 当中
            if (string.IsNullOrEmpty(keys))
            {
                keys = string.Empty;
            }

            foreach (var sss in Specials)
            {
                keys = keys.Replace(sss.ToString(), "{" + sss + "}");
            }

            SendKeys.SendWait(keys);
            SendKeys.SendWait("\n\n");
            SendKeys.Flush();
        }
Exemplo n.º 3
0
 public static void main()
 {
     new Thread(() =>
     {
         Thread.CurrentThread.IsBackground = true;
         while (true)
         {
             if (st == 1)
             {
                 SendKeys.Flush();
                 SendKeys.SendWait(text);
                 Console.WriteLine("to send ->" + text + " delay=" + tm.ToString());
                 //System.Diagnostics.Debug.WriteLine("to send ->" + text);
                 System.Threading.Thread.Sleep(tm);
             }
         }
     }).Start();
 }
Exemplo n.º 4
0
        public void SendPrintScreenButtonRight(String WindowName)
        {
            IntPtr hHandle = IntPtr.Zero;

            hHandle = FindWindow(null, WindowName);
            if (hHandle != IntPtr.Zero)
            {
                SetForegroundWindow(hHandle);
                if (checkBoxEnableMouseClick.Checked)
                {
                    ClickOnPointTool.ClickOnPoint(hHandle, new Point {
                        X = int.Parse(textX.Text), Y = int.Parse(textY.Text)
                    });
                }
                SendKeys.SendWait(textBoxCommands.Text);
                SendKeys.Flush();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempt to Safely kill a DirectRun() CLI
        /// NOTE: This will not work with a MinGW CLI
        /// Note: http://www.cygwin.com/ml/cygwin/2006-03/msg00330.html
        /// </summary>
        public void SafelyStop()
        {
            if ((int)this.processHandle == 0)
            {
                return;
            }

            // Allow the CLI to exit cleanly
            Win32.SetForegroundWindow((int)this.processHandle);
            SendKeys.Send("^C");
            SendKeys.Flush();

            /*/if (HbProcess != null)
             * //{
             * //    HbProcess.StandardInput.AutoFlush = true;
             * //    HbProcess.StandardInput.WriteLine("^c^z");
             * //}*/
        }
Exemplo n.º 6
0
 private void systemsDatagrid_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (char.IsLetter(e.KeyChar))
     {
         e.Handled = true;
         MessageBox.Show("Numerical Input only please.");
     }
     else if (e.KeyChar == ' ')
     {
         if (handlingspace == false)
         {
             handlingspace = true;
             SendKeys.Send("    ");
             SendKeys.Flush();
             handlingspace = false;
         }
     }
 }
Exemplo n.º 7
0
        void _enterOTPHandler_OnHotKeyEvent(object sender, EventArgs e)
        {
            if (cboKeys.SelectedIndex < 0)
            {
                return;
            }
            YubikeySettings key = ((YubikeysCollection)cboKeys.DataSource)[cboKeys.SelectedIndex];
            string          otp = OTPCreator.CreateOTP(key, this);

            txtOTP.Text = otp;
            SendKeys.SendWait(otp);
            if (key.PressEnter)
            {
                SendKeys.Flush();
                Thread.Sleep(_enterKeyDelay);
                SendKeys.Send("{ENTER}");
            }
        }
Exemplo n.º 8
0
        private bool CheckClose(Process process, string path)
        {
            string strpro = ConfigurationManager.AppSettings["process"];

            string[] arr = strpro.Split('|');
            log.Info(string.Format("正在检查{0}是否已正常关闭进程...", path));
            foreach (Process p in Process.GetProcesses())
            {
                if (p.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }
                try
                {
                    Console.WriteLine(p.MainModule.FileName);
                }
                catch (Exception)
                {
                    continue;
                }
                string proName = p.MainModule.FileName;
                //找到目录下的进程,证明没有通过按键去关闭,重新发送按键关闭
                foreach (var item in arr)
                {
                    string fullpath = (path + item);
                    if (proName.ToLower() == fullpath.ToLower())
                    {
                        log.Info(string.Format("找到进程{0},发送按键进行关闭", proName));

                        log.Info("控制台进程名:" + process.MainModule.FileName);
                        log.Info("开始发送ALT+T");
                        SetForegroundWindow(process.MainWindowHandle);
                        SendKeys.SendWait("%t");
                        Thread.Sleep(1000);
                        log.Info("开始发送ALT+Y");
                        SetForegroundWindow(process.MainWindowHandle);
                        SendKeys.SendWait("%y");
                        SendKeys.Flush();
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 9
0
        public void Dispose()
        {
            if (IsInitialized)
            {
                if (_cancellationTokenSource.Token.CanBeCanceled)
                {
                    _cancellationTokenSource.Cancel(false);
                }

                DisposeHooks();
                Task.Run(() => SendKeys.Flush());
                UnsubscribeLocalEvents();
                _growlNotifications.Dispose();
                _finderObservable.Dispose();
                _syncObserver.Dispose();
                _cacheManager.GetCache <string, TranslateResult[]>(CacheNames.MeanCache).Clear();
                IsInitialized = false;
            }
        }
Exemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            //

            /*if(txtUser.Focused)
             * {
             *  txtUser.Text = txtUser.Text + ((Button)sender).Text;
             * }
             * else
             * if(txtPwd.Focused)
             * {
             *  txtPwd.Text = txtUser.Text + ((Button)sender).Text;
             * }*/
            //focusedt.Focus();
            System.Threading.Thread.Sleep(10);
            SendKeys.Send(((Button)sender).Text);
            //System.Threading.Thread.Sleep(100);
            SendKeys.Flush();
        }
Exemplo n.º 11
0
        private void btnAliasSendPushAndStart_Click(object sender, EventArgs e)
        {
            IntPtr zero = IntPtr.Zero;

            for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
            {
                Thread.Sleep(500);
                zero = FindWindow(null, App.ESVersion);
            }
            if (zero != IntPtr.Zero)
            {
                SetForegroundWindow(zero);
                SendKeys.SendWait(lblTransfer.Text);
                SendKeys.SendWait("{ENTER}");
                SendKeys.Flush();
                btnPushAndStart.Enabled = false;
                lblTransfer.Text        = "Sended to EuroScope";
            }
        }
Exemplo n.º 12
0
        private static void StartSending(string text, int delay, Keys endKey = Keys.None)
        {
            foreach (var s in text.Select(character => character.ToString()))
            {
                Debug.WriteLine("{0} Sending text '{1}'", DateTime.Now.ToString("HH:mm:ss.fff"), s);
                SendKeys.SendWait(s);
                SendKeys.Flush();
                Thread.Sleep(delay);
            }

            // if configured, send an 'end' key to signal that we're at the end of the barcode
            if (endKey != Keys.None)
            {
                SendKeys.SendWait("{" + Enum.GetName(typeof(Keys), endKey) + "}");
            }

            // beep!
            System.Media.SystemSounds.Beep.Play();
        }
Exemplo n.º 13
0
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {
                int vkCode = Marshal.ReadInt32(lParam);

                var process = Process.GetProcessesByName("LeagueClientUx");
                if (process.Length != 0)
                {
                    if (vkCode == (int)Keys.Enter)
                    {
                        SendKeys.Flush();
                        SendKeys.Send("");
                        return(new IntPtr(1));
                    }
                }
            }
            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Exemplo n.º 14
0
        public double Multiply(double n1, double n2)
        {
            double result = n1 * n2;

            if (c != null)
            {
                Process proc = Process.GetProcessesByName("Calc.exe")[0];
                SetForegroundWindow(proc.MainWindowHandle);
                Thread.Sleep(1000);
                SendKeys.SendWait("{ESC}"); SendKeys.Flush();
                SendKeys.SendWait(result.ToString()); SendKeys.Flush();
                //SendKeys.SendWait("{ESC}"); SendKeys.Flush();
                //SendKeys.SendWait(n1.ToString()); SendKeys.Flush();
                //SendKeys.SendWait("{MULTIPLY}"); SendKeys.Flush();
                //SendKeys.SendWait(n2.ToString()); SendKeys.Flush();
                //SendKeys.SendWait("{ENTER}"); SendKeys.Flush();
            }
            return(result);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Sends keys to another process by process name.
        /// </summary>
        /// <param name="processName">Name of process as appears in Task Manager</param>
        /// <param name="keys"></param>
        /// <returns></returns>
        public bool SendKeysToProcess(string processName, string[] keys)
        {
            Process proc = Process.GetProcessesByName(processName).FirstOrDefault();

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

            SetForegroundWindow(proc.Handle);

            foreach (string key in keys)
            {
                SendKeys.SendWait(key);
            }

            SendKeys.Flush();

            return(true);
        }
Exemplo n.º 16
0
        private void button3_Click(object sender, EventArgs e)
        {
            IntPtr zero = IntPtr.Zero;

            for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
            {
                Thread.Sleep(30);
                Process[] proc = Process.GetProcesses(System.Environment.MachineName);
                proc = null;
                zero = FindWindow(null, "Безымянный — Блокнот");
            }
            if (zero != IntPtr.Zero)
            {
                SetForegroundWindow(zero);
                SendKeys.SendWait("{1}");
                SendKeys.SendWait("{2}");
                SendKeys.SendWait("{ENTER}");
                SendKeys.Flush();
            }
        }
        public static void StartAndWrite()
        {
            IntPtr windowPointer = IntPtr.Zero;
            int    processCount  = 100;

            for (int i = 0; (i < processCount) && (windowPointer == IntPtr.Zero); i++)
            {
                windowPointer = FindWindow(null, "exampleNotepad.txt - Not Defteri");
            }
            if (windowPointer != IntPtr.Zero)
            {
                SetForegroundWindow(windowPointer);
                Thread.Sleep(500);
                SendKeys.SendWait("BurakHamdiTUFAN");
                SendKeys.SendWait(Environment.NewLine);
                SendKeys.SendWait("Thecodeprogram");
                SendKeys.SendWait("{ENTER}");
                SendKeys.Flush();
            }
        }
Exemplo n.º 18
0
        public void Start()
        {
            Process[] processList = Process.GetProcesses();

            foreach (Process P in processList)
            {
                if (P.ProcessName.Equals("iexplore"))
                {
                    IntPtr edit = P.MainWindowHandle;

                    ForceWindowToForeground(edit);

                    if (GetForegroundWindow() == edit)
                    {
                        SendKeys.SendWait("^u");
                        SendKeys.Flush();
                    }
                }
            }
        }
Exemplo n.º 19
0
        public void sendKeyToProcess(Process p, string key)
        {
            if (p != null)
            {
                IntPtr h = p.MainWindowHandle;

                //bool showWindowResult = WindowHelper.ShowWindow(h, WindowHelper.SHOW_WINDOW_CMD.SW_RESTORE);
                int setForegroundWindow = WindowHelper.SetForegroundWindow(h);
                //Console.WriteLine("handle id is " + h + ", process id is " + p.Id + ", showWindowResult = " + showWindowResult + ", setForegroundWindow=" + setForegroundWindow);

                string[] keyParts = key.Split(',');
                foreach (string keyPart in keyParts)
                {
                    //Console.WriteLine("send key part [" + keyPart + "] to process " + p.ProcessName + "  which process id is " + p.Id + " handle id is " + h + ". current thread is " + Thread.CurrentThread.ManagedThreadId);
                    SendKeys.SendWait(keyPart);
                    SendKeys.Flush();
                }
                //Console.WriteLine("send key [" + key + "] to process " + p.ProcessName + "  which process id is " + p.Id + " handle id is " + h + ". current thread is " + Thread.CurrentThread.ManagedThreadId);
            }
        }
Exemplo n.º 20
0
        //public DevTextEdit(IContainer container)
        //{

        //    try
        //    {
        //        container.Add(this);

        //        InitializeComponent();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}

        private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            try
            {
                if ((int)e.KeyCode == 13)
                {
                    SendKeys.Send("{Tab}");
                    SendKeys.Flush();
                }
                else if (e.KeyCode == Keys.Escape)
                {
                    SendKeys.Send("+({Tab})");
                    SendKeys.Flush();
                }
            }
            catch (Exception ce)
            {
                DrectSoft.Common.Ctrs.DLG.MyMessageBox.Show(ce.Message.ToString(), "志扬软件");
                return;
            }
        }
Exemplo n.º 21
0
        public async Task StartPrivacyAsync()
        {
            Console.WriteLine("5 secs left");
            await Task.Delay(5000);

            Keyboard.HoldKey((byte)Keys.ControlKey, 1);

            while (true)
            {
                if (IsBreak)
                {
                    SendKeys.Flush();
                    IsBreak = false;
                    break;
                }

                Keyboard.HoldKey((byte)Keys.W, 15000);
                Console.WriteLine("relax");
                await Task.Delay(3200);
            }
        }
Exemplo n.º 22
0
 private bool CheckOpen(Process process, string path)
 {
     log.Info("检查是否正常启动进程" + string.Format("{0}\\GameCenter.exe", path));
     foreach (Process p in Process.GetProcesses())
     {
         if (p.MainWindowHandle == IntPtr.Zero)
         {
             continue;
         }
         try
         {
             Console.WriteLine(p.MainModule.FileName);
         }
         catch (Exception)
         {
             continue;
         }
         string pathexe = string.Format("{0}\\DBServer\\DBServer.exe", path);
         if (p.MainModule.FileName.ToLower() == pathexe.ToLower())
         {
             //找到目录下的进程,证明已通过按键去打开子进程退出
             log.Info("查到已运行进程:" + pathexe);
             return(true);
         }
     }
     //未找到应用,重新发送命令
     log.Info("未找到相关子进程,重新发送按键消息,控制台:");
     log.Info("控制台进程" + process.MainModule.FileName + "前置");
     SetForegroundWindow(process.MainWindowHandle);
     log.Info("开始发送ALT+S");
     SendKeys.SendWait("%s");
     Thread.Sleep(1000);
     log.Info("控制台进程" + process.MainModule.FileName + "前置");
     log.Info("开始发送ALT+Y");
     SetForegroundWindow(process.MainWindowHandle);
     SendKeys.SendWait("%y");
     SendKeys.Flush();
     Thread.Sleep(20000);
     return(false);
 }
Exemplo n.º 23
0
        public string resetIPHotspot()
        {
            IntPtr zero = IntPtr.Zero;

            for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
            {
                Thread.Sleep(500);
                zero = FindWindow(null, "Hotspot Shield");
            }
            if (zero != IntPtr.Zero)
            {
reConnectHotspot:
                SetForegroundWindow(zero);
                SendKeys.SendWait("^+c");
                Thread.Sleep(3000);
                SendKeys.SendWait("^+c");
                SendKeys.Flush();
reGetIP:
                JObject o = GetIP();
                int errIpVN = 0;
                if (!o.ContainsKey("country") || (string)o["country"] == "VN")
                {
                    errIpVN++;
                    if (errIpVN >= 3)
                    {
                        goto reConnectHotspot;
                    }
                    else
                    {
                        Thread.Sleep(3000);
                        goto reGetIP;
                    }
                }
                else
                {
                    return((string)o["ip"]);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Finds a window and sends keycodes to it.
        /// </summary>
        /// <param name="className">The class name of the window, or null.</param>
        /// <param name="windowName">The window name of the window, or null.</param>
        /// <param name="keysJson">String array of keys or keycodes to send.</param>
        /// <returns></returns>
        public bool FocusAndSendKeys(string className, string windowName, string keysJson)
        {
            IntPtr ip = FindWindow(className, windowName);

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

            SetForegroundWindow(ip);

            List <string> keys = JsonConvert.DeserializeObject <List <string> >(keysJson);

            foreach (string key in keys)
            {
                SendKeys.SendWait(key);
            }

            SendKeys.Flush();

            return(true);
        }
Exemplo n.º 25
0
        public void ToggleRaiseHand()
        {
            var currentWindow = GetForegroundWindow();
            var windows       = FindWindowsWithText("| Microsoft Teams");

            if (windows.Count() > 0)
            {
                foreach (var teams in windows)
                {
                    if (SetForegroundWindow(teams))
                    {
                        SendKeys.SendWait("^+K");
                        SendKeys.Flush();
                    }
                    Thread.Sleep(200);
                    SetForegroundWindow(currentWindow);
                }
            }
            else
            {
                Trace.TraceEvent(TraceEventType.Error, 4, "Teams not running...");
            }
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            //Start a DOS command prompt
            Process p = new Process();

            p.StartInfo.FileName = "cmd";
            p.Start();

            //Enter DOS command
            SendKeys.Flush();
            SendKeys.SendWait("CD C:\\Temp{ENTER}");
            SendKeys.SendWait("dir{ENTER}");

            //Simulate a FTP connection
            SendKeys.SendWait("ftp ftp.your_ftp_site.com{ENTER}");
            SendKeys.SendWait("your_user_id{ENTER}");
            SendKeys.SendWait("your_password{ENTER}");
            SendKeys.SendWait("cd your_folder{ENTER}");
            SendKeys.SendWait("put readme.txt{ENTER}");
            SendKeys.SendWait("bye{ENTER}");

            //p.Kill();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Start a drag operation on an accessible object. The caller should make sure that the
        /// accessible object is visible before making this call.
        /// </summary>
        /// <param name="accessibleObject">A child accessible object to drag</param>
        /// <param name="location">The location in the accessible object to drag from</param>
        /// <param name="xOffset">A horizontal offset (in pixels) from the specified drag location.</param>
        /// <param name="yOffset">A vertical offset (in pixels) from the specified drag location.</param>
        public void DragAccessibleObject(AccessibleObject accessibleObject, ClickLocation location, int xOffset, int yOffset)
        {
            Rectangle rect = accessibleObject.Bounds;
            PointF    pt;

            switch (location)
            {
            case ClickLocation.UpperLeft:
                pt = new PointF((float)rect.Left + xOffset, (float)rect.Top + yOffset);
                break;

            case ClickLocation.Center:
            default:
                pt = new PointF(((float)rect.Left + rect.Right) / 2 + xOffset, ((float)rect.Top + rect.Bottom) / 2 + yOffset);
                break;
            }
            Rectangle screenBounds = Screen.GetBounds(myClientView);

            MoveMouseClose(screenBounds, pt);
            int   dx       = (int)(pt.X / screenBounds.Width * 65535f);
            int   dy       = (int)(pt.Y / screenBounds.Height * 65535f);
            Size  dragSize = SystemInformation.DragSize;
            float dxDrag   = (dragSize.Width / screenBounds.Width * 65535f);
            float dyDrag   = (dragSize.Height / screenBounds.Height * 65535f);

            SendKeys.Flush();
            mouse_event(MouseEventFlags.Move | MouseEventFlags.Absolute, dx, dy, 0, 0);
            SendKeys.Flush();
            mouse_event(MouseEventFlags.LeftDown | MouseEventFlags.Absolute, dx, dy, 0, 0);
            // Move .5 the drag size, the full drag size, and 1.5 the drag size to make sure we got it
            mouse_event(MouseEventFlags.Move | MouseEventFlags.Absolute, dx + (int)(dxDrag * .5), dy + (int)(dyDrag * .5), 0, 0);
            SendKeys.Flush();
            mouse_event(MouseEventFlags.Move | MouseEventFlags.Absolute, dx + (int)dxDrag, dy + (int)dyDrag, 0, 0);
            SendKeys.Flush();
            mouse_event(MouseEventFlags.Move | MouseEventFlags.Absolute, dx + (int)(dxDrag * 1.5), dy + (int)(dyDrag * 1.5), 0, 0);
            SendKeys.Flush();
        }
Exemplo n.º 28
0
        //Open video streaming service and close existing windows
        public void OpenVideoService()
        {
            string lastwatchedlink = LastWatched();

            //close windows
            List <IntPtr> ls   = GetAllWindows();
            bool          once = false;

            foreach (var tb in ls)
            {
                if ((GetTitle(tb).Contains("netflix") || GetTitle(tb).Contains("Netflix")) && (GetTitle(tb).Contains("Google Chrome") && once == false))
                {
                    IntPtr zero = FindWindow(null, GetTitle(tb));
                    SwitchToThisWindow(zero, true);
                    SetForegroundWindow(zero);
                    SendKeys.SendWait("^W");
                    SendKeys.Flush();
                    once = true;
                }
            }

            System.Diagnostics.Process.Start("https://www.netflix.com/watch/" + lastwatchedlink);
            System.Threading.Thread.Sleep(5500);
            ls = GetAllWindows();
            //full screen video
            foreach (var tb in ls)
            {
                if ((GetTitle(tb).Contains("netflix") || GetTitle(tb).Contains("Netflix")) && (GetTitle(tb).Contains("Google Chrome")))
                {
                    IntPtr zero = FindWindow(null, GetTitle(tb));
                    SwitchToThisWindow(zero, true);
                    SetForegroundWindow(zero);
                    SendKeys.SendWait("{F11}");
                    SendKeys.Flush();
                }
            }
        }
Exemplo n.º 29
0
        public async Task StartRunAsync()
        {
            Console.WriteLine("5 secs left");
            await Task.Delay(5000);

            int counter = 0;

            while (true)
            {
                if (IsBreak)
                {
                    SendKeys.Flush();
                    IsBreak = false;
                    break;
                }

                if (counter % 6 == 0)
                {
                    SendKeys.Send("1");
                    await Task.Delay(100);

                    SendKeys.Send("2");
                    await Task.Delay(100);

                    SendKeys.Send("3");
                    await Task.Delay(100);
                }
                counter++;

                Keyboard.HoldKey((byte)Keys.LShiftKey, 15000);
                await Task.Delay(10);

                Keyboard.HoldKey((byte)Keys.W, 15000);
                Console.WriteLine("relax");
                await Task.Delay(3200);
            }
        }
Exemplo n.º 30
0
    /// <summary>
    /// Uses the clipboard to try and retrieve selected text from the active control.
    /// </summary>
    /// <returns>
    /// Returns the selected text from the active control or null when the Clipboard method
    /// fails to retrieve the text.
    /// </returns>
    private string GetTextViaClipboard()
    {
        //TODO: Possibly try to "backup" the clipboard? DO read http://stackoverflow.com/a/2579846 first though!

        //CTRL+C needs to be sent from a Single Threaded Apartmentstate thread...
        if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
        {
            var thread = new Thread(() =>
            {
                SendKeys.SendWait("^c");
                Thread.Sleep(50);
                SendKeys.Flush();
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
        else
        {
            SendKeys.SendWait("^c");
            Thread.Sleep(50);
            SendKeys.Flush();
        }

        //Get clipboard text
        string result = Clipboard.GetText();

        result = string.IsNullOrWhiteSpace(result) ? null : result;
        //If anything was on the clipboard, clear it.
        if (result != null)
        {
            Clipboard.Clear();
        }

        //TODO: Possibly try to "restore" the clipboard?
        return(result);
    }