Hi all

I am working on application which displays text on the screen as one word of a line at a time. Now words are changing at a set speed of 240ms using ( system.threading.thread.sleep).But i want change words on the screen using left and right arrow key so that if the user does not like the preset speed then the speed can be adjusted using left and right arrow key. At the moment i dont have much idea about how to add keys functionality to my application.
Any help would be much appreciated.


Recommended Answers

All 2 Replies

In the forms properties set KeyPreview to True and then use the Key subs that the form supplies

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    End Sub


Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

    End Sub

You can check which key was pressed using

If e.KeyCode = Keys.Left Then

        End If

To handle the Left key press

Thanks for your reply...code is working beautifully

I am using space key to initialize a thread which starts flashing text on the screen. Now the problem is that if i press the same key again then same thread gets started again and t.abort or t.suspend is not working either.
My idea is pause the thread if the same key is pressed again...like an on off button..

If e.KeyCode = Keys.Space Then

Dim value As Boolean = False

Control.CheckForIllegalCrossThreadCalls = value

Dim t As Thread

t = New Thread(AddressOf rsvp)

If t.IsAlive = False Then


Else : t.Abort()

End If
End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.