Buhus Lucian
Buhus Lucian

Reputation: 1

How to simulate ctrl+enter

I am building a win app that sends some pre-made messages to a chrome window (on a small chat window) button clicks. I was able to do it, but now I want to simulate alt+enter when I click on a specific button.

Here is a part of my code (the button). As you can see, I have SendKeys.Send("^{v}"); here, but it does not do anything...

private void button5_Click(object sender, EventArgs e)
{
    try
    {

        if (string.IsNullOrEmpty(textBox7.Text) && string.IsNullOrEmpty(textBox8.Text)
            || string.IsNullOrEmpty(textBox7.Text) || string.IsNullOrEmpty(textBox8.Text))
        {
            if (string.IsNullOrEmpty(button5.Text))
            {
                MessageBox.Show("Please select a message from the dropbox!");
            }
            else
            {
                Clipboard.SetText(button5.Text.ToString());
                if (string.IsNullOrEmpty(textBox7.Text) && string.IsNullOrEmpty(textBox8.Text)
 || string.IsNullOrEmpty(textBox7.Text) || string.IsNullOrEmpty(textBox8.Text))
                {
                    SendKeys.Send("^{v}");
                    IDataObject iData = Clipboard.GetDataObject();
                    textBox1.Text = (String)iData.GetData(DataFormats.Text);
                }
                else
                {
                    DoMouseClick();
                    SendKeys.Send("^{v}");
                    SendKeys.Send("^{ENTER}");
                    IDataObject iData = Clipboard.GetDataObject();
                    textBox1.Text = (String)iData.GetData(DataFormats.Text);
                }
            }
        }
        else
        {
            int x = Int32.Parse(textBox7.Text);
            int y = Int32.Parse(textBox8.Text);


            Clipboard.SetText(button5.Text.ToString());
            System.Windows.Forms.Cursor.Position = new Point(x, y);
            DoMouseClick();
            SendKeys.Send("^{v}");
            IDataObject iData = Clipboard.GetDataObject();
            textBox1.Text = (String)iData.GetData(DataFormats.Text);
        }
    }
    catch
    {
        //do nothing
    }
}

Upvotes: 0

Views: 1264

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82524

According to official documentation, you should use "^" for ctrl, "%" for alt, and "{ENTER}" (or "~") for Enter.

So to send alt+Enter use SendKeys.Send("%{ENTER}"); or SendKeys.Send("%~");,
and to send ctrl+Enter use SendKeys.Send("^{ENTER}"); or SendKeys.Send("^~");

Upvotes: 1

Related Questions