|
Key trapping
Home » Visual Basic » Introduction to Visual Basic
Key trapping
How do you tell what keys your users are pressing? This tutorial teaches you a rock solid method that you can build in games and advanced applications.
This is extremely easy. Firstly open a new form, or the form that you would like to catch the key presses on.
We can then declare a new procedure:
Code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'space for your code
End Sub
Now this is the only tricky bit, (if you have no understanding of computers what-so-ever). When you press the letter "d" on the keyboard, you are not sending "d" to the comptuer, you are sending a number. Every key on your keyboard has it own, unique, number.
So if I wanted to find out what the key of anything is, I made a form that would tell me. Whenever I pressed a key, it would set the .text property of a disabled input field to the keycode value.
|
More Tutorials by this user
|
|
|