event KeyPress (KeyAscii as Integer, Shift as Integer)

Occurs when the user presses and releases an ANSI key.

 TypeDescription 
   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

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

Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.