1

I need to be able to get access to any highlighted text from any other application in windows, whenever I press a certain hotkey.

I already have the hotkey part running, but I don't know how to find the currently active window and get the highlighted text.

Nor do I know how to replicate a Ctrl+C event using my own shortcut .

Grapping the highlighted text directyly or replicating Ctrl+C event - both would be seen as a solution. As long as the selected text goes into my code.

Can anybody help me?

danededane
  • 415
  • 1
  • 4
  • 14
  • 2
    Possible duplicate of [How to get selected text of any application into a windows form application](https://stackoverflow.com/questions/21460943/how-to-get-selected-text-of-any-application-into-a-windows-form-application) – Avinash Reddy Apr 17 '19 at 08:55
  • @Avinash - I have already read that post, but he is searching for a double mouse click event - I am not . And I also need some more code examples . – danededane Apr 17 '19 at 09:03

1 Answers1

0

I ended up doing like this:

    private void OnHotKeyHandler(HotKey hotKey)
    {
        WinForms.SendKeys.SendWait("^c");
        System.Threading.Thread.Sleep(1000);
        if (Clipboard.ContainsText())
        {
            var selectedText = Clipboard.GetText();
            Debug.Print(selectedText);
        } else
        {
            Debug.Print("Nothing selected");
        }

    }

I know it would be more beautiful to code a clipboard watcher instead of 1000ms sleep. I found the answer here: https://blog.jayway.com/2013/02/06/how-to-get-selected-text-from-another-windows-program/

danededane
  • 415
  • 1
  • 4
  • 14