Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

html - How simulate CTRL+V keystrokes (paste) using C#

How can we simulate CTRL+V keys (paste) using C#?

I have a textbox that hasn't a id for access, for example textbox1.Text = someValue won't work here.
I want to fill that textbox (from clipboard) by clicking on it. For some reasons we exactly need simulate CTRL+V, mean we cannot use external libraries like inputsimulator.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Character vs key

% => alt , + => shift and ^ for to send ctrl key

Original Answer:

Simulation of single modifier key with another key is explained below Step1: Focus the textBox, on which you want to perform two keys and then Step2: send the key for example control-v will be sent like "^{v}". Here is the code

target_textBox.Focus();
SendKeys.Send("^{v}");

target_textBox.Focus(); is needed only when target textbox is not focused at the time of sending key

Update: For sending three keys (two modifying keys plus other key) like to achieve ctrl shift F1 you will send following

^+{F1}

Microsoft Docs Ref


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...