Occurs when the user presses and releases an ANSI key.
Type | Description | |||
KeyAscii as Integer | An integer that returns a standard numeric ANSI keycode. | |||
Shift as Integer | An integer that corresponds to the state of the SHIFT, CTRL, and ALT keys when the key specified in the KeyAsci argument is pressed or released. |
The KeyPress event lets you immediately test keystrokes for validity or for formatting characters as they are typed. Changing the value of the keyascii argument changes the character displayed. 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 does not 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
Syntax for KeyPress event, /NET version, on:
private void KeyPress(object sender,ref short KeyAscii,short Shift) { } Private Sub KeyPress(ByVal sender As System.Object,ByRef KeyAscii As Short,ByVal Shift As Short) Handles KeyPress End Sub |
private void KeyPressEvent(object sender, AxEXPROPERTIESLISTLib._IPropertiesListEvents_KeyPressEvent e) { } void OnKeyPress(short FAR* KeyAscii,short Shift) { } void __fastcall KeyPress(TObject *Sender,short * KeyAscii,short Shift) { } procedure KeyPress(ASender: TObject; var KeyAscii : Smallint;Shift : Smallint); begin end; procedure KeyPressEvent(sender: System.Object; e: AxEXPROPERTIESLISTLib._IPropertiesListEvents_KeyPressEvent); begin end; begin event KeyPress(integer KeyAscii,integer Shift) end event KeyPress Private Sub KeyPressEvent(ByVal sender As System.Object, ByVal e As AxEXPROPERTIESLISTLib._IPropertiesListEvents_KeyPressEvent) Handles KeyPressEvent End Sub Private Sub KeyPress(KeyAscii As Integer,Shift As Integer) End Sub Private Sub KeyPress(KeyAscii As Integer,ByVal Shift As Integer) End Sub LPARAMETERS KeyAscii,Shift PROCEDURE OnKeyPress(oPropertiesList,KeyAscii,Shift) RETURN |
<SCRIPT EVENT="KeyPress(KeyAscii,Shift)" LANGUAGE="JScript"> </SCRIPT> <SCRIPT LANGUAGE="VBScript"> Function KeyPress(KeyAscii,Shift) End Function </SCRIPT> Procedure OnComKeyPress Short llKeyAscii Short llShift Forward Send OnComKeyPress llKeyAscii llShift End_Procedure METHOD OCX_KeyPress(KeyAscii,Shift) CLASS MainDialog RETURN NIL void onEvent_KeyPress(COMVariant /*short*/ _KeyAscii,int _Shift) { } function KeyPress as v (KeyAscii as N,Shift as N) end function function nativeObject_KeyPress(KeyAscii,Shift) return |
Use the KeyPress event to handle keyboard events. The following sample shows how to handle Delete key:
Private Sub PropertiesList1_KeyPress(KeyAscii As Integer, Shift As Integer) If KeyAscii = KeyCodeConstants.vbKeyDelete Then MsgBox PropertiesList1.SelectedProperty.Name End If End Sub