在 VB.net 中发送回车键
Send enter key in VB.net
我想在vb.net中制作一个宏,但唯一的问题是我添加了一个函数来在代码中的任何地方发送回车键,但我不知道如何在代码中执行它。
执行它的代码是:SendKeys.Send(RichTextBox1.Text)
我也试过睡眠然后输入和填充或使用 Ctrl+M 但它没有用我也试过拆分代码但没有任何效果请帮助我。
要发送输入密钥,您需要:
SendKeys.Send("{ENTER}")
这里有更多信息:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=netframework-4.6
有延迟:
Private Sub SendKeyWithDelay(millisecByNow As Integer, keyString As String)
Try
Dim t As Timer = New Timer With {
.Interval = millisecByNow
}
AddHandler t.Tick, Sub(tmr As Object, e As EventArgs)
CType(tmr, Timer).Stop()
CType(tmr, Timer).Dispose()
SendKeys.Send(keyString)
End Sub
t.Start()
Catch ex As Exception
'log here
End Try
End Sub
用法:
SendKeyWithDelay(500, "{ENTER}")
我把代码改成了
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
对我来说非常好 现在感谢您的帮助!我希望如果有人看到这个遇到同样的问题,他们会读到这个。
我想在vb.net中制作一个宏,但唯一的问题是我添加了一个函数来在代码中的任何地方发送回车键,但我不知道如何在代码中执行它。
执行它的代码是:SendKeys.Send(RichTextBox1.Text)
我也试过睡眠然后输入和填充或使用 Ctrl+M 但它没有用我也试过拆分代码但没有任何效果请帮助我。
要发送输入密钥,您需要:
SendKeys.Send("{ENTER}")
这里有更多信息: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=netframework-4.6
有延迟:
Private Sub SendKeyWithDelay(millisecByNow As Integer, keyString As String)
Try
Dim t As Timer = New Timer With {
.Interval = millisecByNow
}
AddHandler t.Tick, Sub(tmr As Object, e As EventArgs)
CType(tmr, Timer).Stop()
CType(tmr, Timer).Dispose()
SendKeys.Send(keyString)
End Sub
t.Start()
Catch ex As Exception
'log here
End Try
End Sub
用法:
SendKeyWithDelay(500, "{ENTER}")
我把代码改成了
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
对我来说非常好 现在感谢您的帮助!我希望如果有人看到这个遇到同样的问题,他们会读到这个。