[Visual Basic .NET] |
---|
Public Event KeyPress( _
ByRef KeyAscii As Integer _
)
|
[C#] |
---|
public void KeyPress(
|
[Managed C++] |
---|
public: void KeyPress(
|
[Java] |
---|
public keyPress(
|
[Unmanaged C++] |
---|
public: HRESULT KeyPress(
|
- KeyAscii
- An integer that returns a standard numeric ANSI keycode. KeyAscii is passed by reference; changing it sends a different character to the control. Changing KeyAscii to 0 cancels the keystroke so the control receives no character.
A KeyPress event can involve any printable keyboard character, the CTRL key combined with a character from the standard alphabet or one of a few special characters, and the ENTER or BACKSPACE key. A KeyPress event procedure enables you to immediately test keystrokes for validity or to format characters as they're typed. Changing the value of the KeyAscii argument changes the character received by the control.
In Visual Basic 6.0 you can convert the KeyAscii argument into a character by using the expression:
Chr(KeyAscii)
You can then perform string operations and translate the character back to an ANSI number that the control can interpret by using the expression:
KeyAscii =
Asc(char)
Use KeyDown and KeyUp event procedures to handle any keystroke not recognized by KeyPress, such as function keys, editing keys, navigation keys, and any combinations of these with keyboard modifiers. Unlike the KeyDown and KeyUp events, KeyPress doesn't indicate the physical state of the keyboard; instead, it passes a character.
KeyPress interprets the uppercase and lowercase of each character as separate key codes and, therefore, as two separate characters. KeyDown and KeyUp interpret the uppercase and lowercase of each character by means of two arguments: KeyCode, which indicates the physical key (thus returning A and a as the same key), and Shift, which indicates the state of shift+key and therefore returns either A or a.
In VB.NET the KeyPress event is shown as "xxxxxxxx_KeyPressEvent" in the IDE.
[Visual Basic .NET] | Copy Code | |
---|---|---|
|