...

View Full Version : How do I link arrow keys to code in VB.NET?



meandmymachine
07-12-2003, 02:26 PM
Hello there

I'm trying to write code that responds to the user manipulating two of the arrow keys (you know, the four keys just under the delete, end and page down keys). The following code compiles okay but it doesn't do anything. I just wondered how I should modify it. All contributions gratefully accepted.

meandmymachine

Heres the code:

Dim vbKeyRight As Integer
Dim vbKeyLeft As Integer

Private Sub KeyPress1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = vbKeyRight Then
MsgBox("Right Key Pressed!")
End If
End Sub

Private Sub KeyPress2_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = vbKeyLeft Then
MsgBox("Left Key Pressed!")
End If
End Sub

oracleguy
07-12-2003, 09:10 PM
You shouldn't have to declared vbKeyRight and vbKeyLeft if they are constants... How about changing it to:

Private Sub KeyPress1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
MsgBox(KeyCode)
End Sub

Then press the arrow keys and see what you get, that should give you the keycode for it.

If that doesn't work you could use DirectInput. You'd have to if you want to be able to process multiple keys at the same time.

xbrem19
10-19-2009, 11:16 AM
I put mentioned code into VB editor pressed "play" and nothing happened. What is wrong?
M.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum