By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

VB.net keytraps help

P: 1
Hi, I am using this to make the object 'Pos' move around the form which has buttons on it. When a button is pressed this stops working, is there anyway to stop this from happening, also using the arrow keys does not work and stops the wasd keys from working. I have tried enabling and disabling the buttons, but this doest work.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub trapKey(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
  2.  
  3.             If e.KeyData = Keys.S Or e.KeyData = Keys.Down Then
  4.  
  5.                 If Pos.Top < 675 Then
  6.                     Pos.Top = Pos.Top + 5
  7.                 End If
  8.  
  9.             ElseIf e.KeyData = Keys.W Or e.KeyData = Keys.Up Then
  10.  
  11.                 If Pos.Top > 215 Then
  12.                     Pos.Top = Pos.Top - 5
  13.                 End If
  14.  
  15.  
  16.  
  17.             ElseIf e.KeyData = Keys.A Or e.KeyData = Keys.Left Then
  18.  
  19.                 If Pos.Left > 20 Then
  20.                     Pos.Left = Pos.Left - 5
  21.                 End If
  22.  
  23.  
  24.             ElseIf e.KeyData = Keys.D Or e.KeyData = Keys.Right Then
  25.  
  26.                 If Pos.Left < 482 Then
  27.                     Pos.Left = Pos.Left + 5
  28.                 End If
  29.  
  30.             End If
  31.  
  32.     End Sub
Thanks
Apr 1 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.