943,548 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 9074
  • VB.NET RSS
Nov 30th, 2008
0

Programming keyboard keys in vb.net

Expand Post »
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.

Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harrybern is offline Offline
6 posts
since Nov 2008
Nov 30th, 2008
0

Re: Programming keyboard keys in vb.net

In the forms properties set KeyPreview to True and then use the Key subs that the form supplies
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  2.  
  3. End Sub
AND/OR
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  2.  
  3. End Sub
You can check which key was pressed using
VB.NET Syntax (Toggle Plain Text)
  1. If e.KeyCode = Keys.Left Then
  2.  
  3. End If
To handle the Left key press
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Dec 2nd, 2008
0

Re: Programming keyboard keys in vb.net

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

t.Start()


Else : t.Abort()

End If
End If
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harrybern is offline Offline
6 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: create a .cab file
Next Thread in VB.NET Forum Timeline: Help Regarding CrystalReports





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC