Search code examples
.netvb.netsendkeysenter

Send enter key in VB.net


I want to make a macro in vb.net but the only problem is that I added a function to send the enter key anywhere in the code and I don't know how to execute it in the code. the code to execute it is: SendKeys.Send(RichTextBox1.Text) i also tried it with sleep and then enter and stuff or with Ctrl+M but it didn't work I also tried splitting the code but nothing works please help me.


Solution

  • I changed the code to

    Private Sub SendKeyWithDelay(sleeptime As Integer, text As String)
        Dim out() As String
        out = text.Split(" ")
        For i = 0 To out.Length - 1 Thread.Sleep(sleeptime) 
            SendKeys.Send(out(i))
        Next 
    End Sub
    

    works perfectly for me now thanks for the help! I hope if someone looks at this with the same problem they will read this.