Key Property
Collapse the table of content
Expand the table of content

KeyEventArgs.Key Property

 

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:
© 2016 Microsoft