Home

Keyboard Events

 

Introduction

A keyboard is a hardware object attached to the computer. By default, it is used to enter recognizable symbols, letters, and other characters on a control. Each key on the keyboard displays a symbol, a letter, or a combination of those, to give an indication of what the key could be used for.

The user typically presses a key, which sends a signal to a program. The signal is analyzed to find its meaning. If the program or control that has focus is equipped to deal with the signal, it may produce the expected result. If the program or control cannot figure out what to do, it ignores the action.

Each key has a code that the operating system can recognize.

 

The Key Down Message

When a keyboard key is pressed, a message called KeyDown is sent. KeyDown is a KeyEventArgs type interpreted through the KeyEventHandler event whose syntax is:

Public Event KeyDown As KeyEventHandler

The KeyEventHandler event is carried by the KeyEventArgs class defined in the System.Windows.Forms namespace through the KeyEventHandler delegate: 

Public Delegate Sub KeyEventHandler(sender As Object, e As KeyEventArgs)

When you initiate this event, its KeyEventArgs argument provides as much information as possible to implement an appropriate behavior.

The Key Up Message

As opposed to the key down message that is sent when a key is down, the KeyUp message is sent when the user releases the key. This event also is of type KeyEventArgs:

The Key Press Message

When the user presses a key, the KeyPress message is sent. Unlike the other two keyboard messages, the key pressed for this event should (must) be a character key. This event is handled by the KeyPressEventHandler event whose syntax is:

Public Event KeyPress As KeyPressEventHandler

The KeyPress event is carried by a KeyPressEventArgs class. The Handled property identifies whether this event was handled. The KeyChar property identifies the key that was pressed. It must be a letter or a recognizable symbol. Lowercase alphabetic characters, digits, and the lower base characters such as ; , ‘ [ ] - = / are recognized as they are. For an uppercase letter or an upper base symbols, the user must press Shift + the key. The character would be identified as one entity. This means that the symbol % typed with Shift + 5 is considered as one character.

 

 

Home Copyright © 2008 FunctionX, Inc. Home