Key Property

KeyEventArgs.Key Property


Gets the keyboard key associated with the event.

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

Public ReadOnly Property Key As Key

Property Value

Type: System.Windows.Input.Key

The Key referenced by the event.

The following example creates a KeyEventHandler and checks whether the key associated with the KeyEventArgs is the Return key.

Private Sub OnKeyDownHandler(ByVal sender As Object, ByVal e As KeyEventArgs)
    If (e.Key = Key.Return) Then
        textBlock1.Text = "You Entered: " + textBox1.Text
    End If
End Sub

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft