Browse All Articles
> Visual Basic.NET 2008 - Capturing Keys in VB.NET
Hello Experts Exchange Users!
This is my first tutorial, so I hope that you like it!
Goal : Create a program to get the keys entered into the form
Programming Language : Visual Basic.NET 2008 SP1
The first thing that we must do to reach our goal is create a new project. This can be done by clicking File > New Project or by pressing Control and N on your keyboard.
Name the project "Capturing Keys in VB.NET" or anything else that you want.
Customize the form in anyway that you want.
Add two labels and name them "lblKeyCode" and "lblKeyValue".
Select the form, enter the list of handlers and double-click the "KeyDown" handler.
In the "KeyDown" handler, you must put the following code:
lblKeyCode.Text = e.KeyCode.ToString
Explanation for Step 6
lblKeyValue.Text = e.KeyValue.ToString
The code "lblKeyCode.Text = e.KeyCode.ToString" will set the first label to the internal key name. (eg. "A" or "Delete")
The code "lblKeyValue.text = e.KeyValue.ToString" will set the second label to the value of the key (eg. "19" or "49")
Press the debug button and press any key on your keyboard
The value of the labels should change, depending on which key you press
- Daniel Sage