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

Exception or error:

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.

How to solve:

Code for modifying keys (See update below for more than two keys)

alt = % , shift = + and ctrl = ^

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(); is needed only when target textbox is not focused at the time of sending key


For sending three keys (two modifying keys plus other key) like ctrl shift F1 you will do


Microsoft Docs Ref


Why don’t you override the TextBox OnClick event than when the event is called, set the Text property to Clipboard.GetText()


private void textBox1_Click ( object sender, EventArgs e )
        textBox1.Text = Clipboard.GetText ();


This function is already built in: TextBoxBase.Paste()



some JS do not permit to change value in usual way

inputList[21].SetAttribute("value", txtEMail.Text);

you should try something like this:

inputElement.InvokeMember("click"); //sometimes helpfull

//but not “^{v}”

Leave a Reply

Your email address will not be published. Required fields are marked *