ID:188738
 
How might I trigger a keypress event in Visual Basic? I have the arrow keys in mind at the moment for moving around a map. I typed in "KeyDown" into the code window and it was accepted (I used a lower case 'D' and it changed when I hit enter) so I am assuming it has something to do with that, though I don't know exactly how to accomplish it. (I would search through a helpfile, but for some odd reason my version doesn't have one.)

Thanks in advance for any help.

Also, does anyone know where I might find a list of Visual Basic variables and functions online? Something similar to DM's help file would be extremely helpful.
KeyUp, KeyPress, and KeyDown are the events you can use. I'd copy out the entries from the help for you (or just give you the help file), but I don't have it installed at the moment.

There should be tutorials/references on the net somewhere, try Google.
In response to Crispy
Crispy wrote:
I'd copy out the entries from the help for you (or just give you the help file), but I don't have it installed at the moment.

Do that, I couldn't install MSDN at all when I got VB. That's extremley annoying. I guess I shouldn't get proffesional edition next time, as it comes with seven disks. What would I do with seven disks? Pfft.
Loduwijk wrote:
How might I trigger a keypress event in Visual Basic? I have the arrow keys in mind at the moment for moving around a map. I typed in "KeyDown" into the code window and it was accepted (I used a lower case 'D' and it changed when I hit enter) so I am assuming it has something to do with that, though I don't know exactly how to accomplish it. (I would search through a helpfile, but for some odd reason my version doesn't have one.)

Thanks in advance for any help.

You should be able to call the KeyPress functions of the form objects, by simply doing something such as 'Text1_KeyPress(vbKeyReturn)'.

Also, does anyone know where I might find a list of Visual Basic variables and functions online? Something similar to DM's help file would be extremely helpful.

http://msdn.microsoft.com

~>Volte
In response to Volte
Volte wrote:
You should be able to call the KeyPress functions of the form objects, by simply doing something such as 'Text1_KeyPress(vbKeyReturn)'.

I think he wants to detect keypress events, not trigger them. =)
In response to Crispy
You have to define the keypress events in a sub, and then define which keypress your looking to modify. I don't exactly remember, its been awhile since I worked with VB.
How might I trigger a keypress event in Visual Basic? I have the arrow keys in mind at the moment for moving around a map. I typed in "KeyDown" into the code window and it was accepted (I used a lower case 'D' and it changed when I hit enter) so I am assuming it has something to do with that, though I don't know exactly how to accomplish it. (I would search through a helpfile, but for some odd reason my version doesn't have one.)

I advise againt using the keypress event since that doesn't allow you to handle people holding keys down well or people holding multiple keys. Here's how I would do it.

Dim keyUp As Boolean
Dim keyDown As Boolean
Dim keyLeft As Boolean
Dim keyRight As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
keyUp = True
End If
If KeyCode = vbKeyDown Then
keyDown = True
End If
If KeyCode = vbKeyLeft Then
keyLeft = True
End If
If KeyCode = vbKeyRight Then
keyRight = True
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
keyUp = False
End If
If KeyCode = vbKeyDown Then
keyDown = False
End If
If KeyCode = vbKeyLeft Then
keyLeft = False
End If
If KeyCode = vbKeyRight Then
keyRight = False
End If
End Sub

Then if you need to check the if any of the direction keys are held down you check the variables. For a game you'd probably want to handle this with a timer.

Also, does anyone know where I might find a list of Visual Basic variables and functions online? Something similar to DM's help file would be extremely helpful.

msdn.microsoft.com

[edit] Oh and the keyup and keydown events refer to pressing any key down and releasing any key not using the up and down keys specifically.