Programming keyboard keys in vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 6
Reputation: harrybern is an unknown quantity at this point 
Solved Threads: 0
harrybern harrybern is offline Offline
Newbie Poster

Programming keyboard keys in vb.net

 
0
  #1
Nov 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 169
Reputation: ptaylor965 is an unknown quantity at this point 
Solved Threads: 19
Sponsor
ptaylor965's Avatar
ptaylor965 ptaylor965 is offline Offline
Junior Poster

Re: Programming keyboard keys in vb.net

 
0
  #2
Nov 30th, 2008
In the forms properties set KeyPreview to True and then use the Key subs that the form supplies
  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
  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
  1. If e.KeyCode = Keys.Left Then
  2.  
  3. End If
To handle the Left key press
Peter Taylor
Visual Basic.NET Application Developer

TaylorsNet
http://www.taylorsnet.co.uk
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: harrybern is an unknown quantity at this point 
Solved Threads: 0
harrybern harrybern is offline Offline
Newbie Poster

Re: Programming keyboard keys in vb.net

 
0
  #3
Dec 2nd, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC