<

Visual Basic.NET 2008 - Capturing Keys in VB.NET

Published on
5,510 Points
2,510 Views
Last Modified:
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

Step 1
  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.

Step 2
  Name the project "Capturing Keys in VB.NET" or anything else that you want.

 Figure 1 - Name the projectStep 3
  Customize the form in anyway that you want.

  Figure 2 - Customize the formStep 4
  Add two labels and name them "lblKeyCode" and "lblKeyValue".

  Figure 3 - Add two labelsStep 5
  Select the form, enter the list of handlers and double-click the "KeyDown" handler.

  Figure 4 - Create a "KeyDown" handlerStep 6
  In the "KeyDown" handler, you must put the following code:
 
lblKeyCode.Text = e.KeyCode.ToString

Open in new window

 and
 
lblKeyValue.Text = e.KeyValue.ToString

Open in new window


Explanation for Step 6
  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")

Step 7
  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
0
Comment
Author:Daniel-Sage
1 Comment

Expert Comment

by:rtrajkov
Does this work even if the program is running in the background?
0

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Join & Write a Comment

From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
Basic Overview of office 365 user portal

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month