KeyEventArgs.Key Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the keyboard key associated with the event.

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

public Key Key { get; }

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 void OnKeyDownHandler(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}

.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: