AfterKeyPress Event
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

TextDocumentKeyPressEventsClass.AfterKeyPress Event 

Raised after a key press has been handled and the editor has processed the entered text.

Namespace: EnvDTE80
Assembly: EnvDTE80 (in envdte80.dll)

public virtual event _dispTextDocumentKeyPressEvents_AfterKeyPressEventHandler _dispTextDocumentKeyPressEvents_Event.AfterKeyPress
J# supports the use of explicit interface implementations, but not the declaration of new ones.
JScript supports the use of events, but not the declaration of new ones.

The user may not cancel the key press or its resulting behavior.

This simple macro example displays a message box every time you type the character, 1, in a text document. Copy this code to the EnvironmentModule in the Macros integrated development environment (IDE) in Visual Studio. For more information about how to write EnvironmentModule macros, see How to: Handle Environment Events in Macros.

Private Sub TextDocumentKeyPressEvents_AfterKeyPress(ByVal Keypress _
 As String, ByVal Selection As EnvDTE.TextSelection, _
 ByVal InStatementCompletion As Boolean) _
 Handles TextDocumentKeyPressEvents.AfterKeyPress
    If (Keypress = "1") Then
        MsgBox("You pressed 1.")
    End If
End Sub
© 2015 Microsoft