简体   繁体   中英

Programmatically trigger a copy or paste in c#

I have a program that I'm working on that register global hotkeys

I would like to use that ability to trigger highlighted text or data to be copied to the clipboard and then read from the clipboard into a variable in my program

which i will later use in reverse to paste it back out.

(example ctrl+1 copys to quque #1 and alt+1 pasts what is in quque 1)

thanks so much.

You mean... like this?

Clipboard.SetText("whatever");

...or are you talking about copying text from any arbitrary window in another application? The latter is not trivial at all.

SendKeys.Send("^c");

Well, you could possibly do a P/Invoke with SendMessage or even better SendInput Win32 APIs. That should be enough for you to simulate almost any key strokes.

James

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM