-1

I'm experimenting with a simple auto typer. I've made several of these before, but have never received this error. I just want to be able to send the text within textbox3 to the currently focused window. Here's the code :

code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If Timer1.Enabled = False Then
        Timer1.Enabled = True
        Button2.Text = "Stop"
    ElseIf Timer1.Enabled = True Then
        Timer1.Enabled = False
        Button2.Text = "Send"
    End If


End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If CheckBox1.Checked = True Then
        SendKeys.Send("{ENTER}")
        SendKeys.Send(TextBox3.Text)
    ElseIf CheckBox1.Checked = False Then
        SendKeys.Send(TextBox3.Text)
    End If
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
    Timer1.Interval = NumericUpDown1.Value
End Sub

Thats the only portion involving the sendkeys method and timer. Some of the text within textbox3 comes from variables as well, if that helps to know.

Community
  • 1
  • 1
Jake2k13
  • 231
  • 3
  • 8
  • 23
  • 1
    What does `TextBox3` contain at the time? This quote from the documentation seems relevant: `To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.` – jmcilhinney Jul 08 '14 at 06:18

1 Answers1

1

In another (now deleted) question, you claim the error happens here:

SendKeys.Send(Textbox3.Text)

Well, what is the value of Textbox3.Text which produces the error? According to the documentation, specifying repeated keys would involve a key token and an integer separate by a space, enclosed in curly braces. Something like "{LEFT 42}" or "{h 10}". So if you're entering something like "{A B}" then it's going to fail.

Presumably the runtime value of Textbox3.Text has an invalid format for SendKeys.Send(), or is mis-using characters which are otherwise reserved for the format string.

David
  • 208,112
  • 36
  • 198
  • 279