Send Text in Clipboard to Application like Notepad (C# or Powershell) -


I want to send text to the clipboard, in an application form. For example, I'm working on a text file in Notepad, and I want to copy one part to a new file..I want to copy it to the clipboard and then launch a hotkey to launch an app I want to use that which has copied text for a new example of Notepad.

How can I get it in C # or PowerShell?

Solution: Use of AutoHotkey

  ^ + C :: Send ^ c Notepad WinWait Untitled - Notepad WinActivate Send ^ v Return  

I have 2 solutions, one that uses PowerShell, uses the other.

Autohotkey version

I will use it one;) You define custom keys; Force action for keys; My file contains this code :

  ^ # n :: Run, Notepad WinWaitActive Untitled - Send Notepad2! E send p returns  

It runs Notepad 2 and then simulates by pressing Alting + E and P. She pastes the string in the same way as you press it yourself. For some reason I had some problems with 'pressing' Ctrl + V (I do not remember anymore). Take a look at Autohotkey's website for more information.

PowerShell version

You must use it as an editor. With the switch / c , it launches Notepad 2 and pastes the text from the clipboard.

To make it more useful, I define the tnp function like this: (Note that you need to run a parcel with the -sta parameter , Otherwise they will not work propely)

  function tnp {param ([parameter (mandatory = $ true, valueFromPipeline = $ true)] [object] $ input object) {$ Objs = @ ()} Process {$ objs + $ $ InputObject} End {$ old = get-clipboard # store current value $ objs start} Out-String-Wide 1000 | Set-clipboard notepad / c sleep-$ 500 million dollars old. Set-Clipboard # Restore Original Value}} Function Set-Clipboard {Ultimate ([Parameter (mandatory = $ true, valuefrappipeline = $ right, position = 0)] [object] $ s) {$ sb = new-object text .StringBuilder} process {$ s | % {If ($ sb.Length -gt 0) {$ null = $ sb.AppendLine (); } $ Null = $ sb.Append ($ _)}} {end-type -a system.windows.forms; End} [Windows.forms.clipboard] :: settext ($ sb.Tostring ())} function go-clipboard {add-type - a system.windows.forces [windows.forms.clipboard] :: GetText ()}  

With these functions you can run something like this:

  # list of members, notepad 2 opens and pastes content (members List of) (Receipt Date) | Village | In other words - If some information will be returned and formatted on the screen, then you can get it and paste it on the Notepad. 


Comments