I have a form with one textbox and a timer on it. Other than the Form Designer generated code, this is all that is in my form:
If I try to type in the TextBox, nothing appears, which is as it should be. But, I would expect the word 'hello' to appear in my textbox every 5 seconds (the timer is set to 5000). But, it does not. Also, if I add a break point at either the Timer1_Tick event or the TextBox1_KeyPress event, the application will actually lock up when the timer event hits! I am assuming that it has something to do with the fact that it is a timer doing the sending. Why is this happening? Is there some way around it while still using SendKeys?
Visual Basic:
Private AllowKeys As Boolean
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Not AllowKeys Then
e.Handled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AllowKeys = False
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
AllowKeys = True
SendKeys.Send("hello")
AllowKeys = False
End Sub
If I try to type in the TextBox, nothing appears, which is as it should be. But, I would expect the word 'hello' to appear in my textbox every 5 seconds (the timer is set to 5000). But, it does not. Also, if I add a break point at either the Timer1_Tick event or the TextBox1_KeyPress event, the application will actually lock up when the timer event hits! I am assuming that it has something to do with the fact that it is a timer doing the sending. Why is this happening? Is there some way around it while still using SendKeys?