0

So my current project is comming to an end.

But I have an issue, i need to get a selection from any window and insert that into my current method, and then paste a new string into the selection.

This means that if i mark the following "This is a simple line", and i press my shortcut, i want "This is a simple line" to go into my method, and transform the text to "This line is more advanced", when i press my global hotkey.

Currently the method takes a string and returns a string (So the method works fine), i just need for it to copy the selection, do the method and then paste the new text, when i use my shortcut.

Any ideas?

  • 1
    You'll need to have the Windows handle of the dialog and control for which you want to get and set the text, and then use the Windows API [to get and set the selected text](https://stackoverflow.com/questions/2251578/how-do-i-get-the-selected-text-from-the-focused-window-using-native-win32-api) by emulating Ctrl+C and Ctrl+V. – Matthew Watson Jun 08 '22 at 08:45

2 Answers2

1

I've solved it, the "fix" was just to simulate/emulate the "ctrt + c" "ctrl + v" shortcut in the project. I've gotten my inspiration from: This youtube video. Big thanks to "Matthew Watson" for the suggestion

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – MD. RAKIB HASAN Jun 10 '22 at 08:34
0
Clipboard.SetText(textBox1.Text); //To copy your text to your clipboard
Clipboard.GetText(); //To get your text from your clipboard

Credit: https://stackoverflow.com/a/10140582/12345062