Expand Minimize

Key Enumeration

Specifies the possible key values on a keyboard.

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

[TypeConverterAttribute(typeof(KeyConverter))]
public enum Key
<object property="enumerationMemberName" .../>

Member nameDescription
AThe A key.
AbntC1The ABNT_C1 (Brazilian) key.
AbntC2The ABNT_C2 (Brazilian) key.
AddThe Add key.
AppsThe Application key (Microsoft Natural Keyboard).
AttnThe ATTN key.
BThe B key.
BackThe Backspace key.
BrowserBackThe Browser Back key.
BrowserFavoritesThe Browser Favorites key.
BrowserForwardThe Browser Forward key.
BrowserHomeThe Browser Home key.
BrowserRefreshThe Browser Refresh key.
BrowserSearchThe Browser Search key.
BrowserStopThe Browser Stop key.
CThe C key.
CancelThe Cancel key.
CapitalThe Caps Lock key.
CapsLockThe Caps Lock key.
ClearThe Clear key.
CrSelThe CRSEL key.
DThe D key.
D0The 0 (zero) key.
D1The 1 (one) key.
D2The 2 key.
D3The 3 key.
D4The 4 key.
D5The 5 key.
D6The 6 key.
D7The 7 key.
D8The 8 key.
D9The 9 key.
DbeAlphanumericThe DBE_ALPHANUMERIC key.
DbeCodeInputThe DBE_CODEINPUT key.
DbeDbcsCharThe DBE_DBCSCHAR key.
DbeDetermineStringThe DBE_DETERMINESTRING key.
DbeEnterDialogConversionModeThe DBE_ENTERDLGCONVERSIONMODE key.
DbeEnterImeConfigureModeThe DBE_ENTERIMECONFIGMODE key.
DbeEnterWordRegisterModeThe DBE_ENTERWORDREGISTERMODE key.
DbeFlushStringThe DBE_FLUSHSTRING key.
DbeHiraganaThe DBE_HIRAGANA key.
DbeKatakanaThe DBE_KATAKANA key.
DbeNoCodeInputThe DBE_NOCODEINPUT key.
DbeNoRomanThe DBE_NOROMAN key.
DbeRomanThe DBE_ROMAN key.
DbeSbcsCharThe DBE_SBCSCHAR key.
DeadCharProcessedThe key is used with another key to create a single combined character.
DecimalThe Decimal key.
DeleteThe Delete key.
DivideThe Divide key.
DownThe Down Arrow key.
EThe E key.
EndThe End key.
EnterThe Enter key.
EraseEofThe ERASE EOF key.
EscapeThe ESC key.
ExecuteThe Execute key.
ExSelThe EXSEL key.
FThe F key.
F1The F1 key.
F10The F10 key.
F11The F11 key.
F12The F12 key.
F13The F13 key.
F14The F14 key.
F15The F15 key.
F16The F16 key.
F17The F17 key.
F18The F18 key.
F19The F19 key.
F2The F2 key.
F20The F20 key.
F21The F21 key.
F22The F22 key.
F23The F23 key.
F24The F24 key.
F3The F3 key.
F4The F4 key.
F5The F5 key.
F6The F6 key.
F7The F7 key.
F8The F8 key.
F9The F9 key.
FinalModeThe IME Final mode key.
GThe G key.
HThe H key.
HangulModeThe IME Hangul mode key.
HanjaModeThe IME Hanja mode key.
HelpThe Help key.
HomeThe Home key.
IThe I key.
ImeAcceptThe IME Accept key.
ImeConvertThe IME Convert key.
ImeModeChangeThe IME Mode change request.
ImeNonConvertThe IME NonConvert key.
ImeProcessedA special key masking the real key being processed by an IME.
InsertThe Insert key.
JThe J key.
JunjaModeThe IME Junja mode key.
KThe K key.
KanaModeThe IME Kana mode key.
KanjiModeThe IME Kanji mode key.
LThe L key.
LaunchApplication1The Launch Application1 key.
LaunchApplication2The Launch Application2 key.
LaunchMailThe Launch Mail key.
LeftThe Left Arrow key.
LeftAltThe left ALT key.
LeftCtrlThe left CTRL key.
LeftShiftThe left Shift key.
LineFeedThe Linefeed key.
LWinThe left Windows logo key (Microsoft Natural Keyboard).
MThe M key.
MediaNextTrackThe Media Next Track key.
MediaPlayPauseThe Media Play Pause key.
MediaPreviousTrackThe Media Previous Track key.
MediaStopThe Media Stop key.
MultiplyThe Multiply key.
NThe N key.
NextThe Page Down key.
NoNameA constant reserved for future use.
NoneNo key pressed.
NumLockThe Num Lock key.
NumPad0The 0 key on the numeric keypad.
NumPad1The 1 key on the numeric keypad.
NumPad2The 2 key on the numeric keypad.
NumPad3The 3 key on the numeric keypad.
NumPad4The 4 key on the numeric keypad.
NumPad5The 5 key on the numeric keypad.
NumPad6The 6 key on the numeric keypad.
NumPad7The 7 key on the numeric keypad.
NumPad8The 8 key on the numeric keypad.
NumPad9The 9 key on the numeric keypad.
OThe O key.
Oem1The OEM 1 key.
Oem102The OEM 102 key.
Oem2The OEM 2 key.
Oem3The OEM 3 key.
Oem4The OEM 4 key.
Oem5The OEM 5 key.
Oem6The OEM 6 key.
Oem7The OEM 7 key.
Oem8The OEM 8 key.
OemAttnThe OEM ATTN key.
OemAutoThe OEM AUTO key.
OemBackslashThe OEM Backslash key.
OemBackTabThe OEM BACKTAB key.
OemClearThe OEM Clear key.
OemCloseBracketsThe OEM Close Brackets key.
OemCommaThe OEM Comma key.
OemCopyThe OEM COPY key.
OemEnlwThe OEM ENLW key.
OemFinishThe OEM FINISH key.
OemMinusThe OEM Minus key.
OemOpenBracketsThe OEM Open Brackets key.
OemPeriodThe OEM Period key.
OemPipeThe OEM Pipe key.
OemPlusThe OEM Addition key.
OemQuestionThe OEM Question key.
OemQuotesThe OEM Quotes key.
OemSemicolonThe OEM Semicolon key.
OemTildeThe OEM Tilde key.
PThe P key.
Pa1The PA1 key.
PageDownThe Page Down key.
PageUpThe Page Up key.
PauseThe Pause key.
PlayThe PLAY key.
PrintThe Print key.
PrintScreenThe Print Screen key.
PriorThe Page Up key.
QThe Q key.
RThe R key.
ReturnThe Return key.
RightThe Right Arrow key.
RightAltThe right ALT key.
RightCtrlThe right CTRL key.
RightShiftThe right Shift key.
RWinThe right Windows logo key (Microsoft Natural Keyboard).
SThe S key.
ScrollThe Scroll Lock key.
SelectThe Select key.
SelectMediaThe Select Media key.
SeparatorThe Separator key.
SleepThe Computer Sleep key.
SnapshotThe Print Screen key.
SpaceThe Spacebar key.
SubtractThe Subtract key.
SystemA special key masking the real key being processed as a system key.
TThe T key.
TabThe Tab key.
UThe U key.
UpThe Up Arrow key.
VThe V key.
VolumeDownThe Volume Down key.
VolumeMuteThe Volume Mute key.
VolumeUpThe Volume Up key.
WThe W key.
XThe X key.
YThe Y key.
ZThe Z key.
ZoomThe ZOOM key.

Information pertaining to key input can be obtained in several different ways in WPF. Key-related events, such as KeyDown and KeyUp, provide key state information through the KeyEventArgs object that is passed to the event handler. Key state information can also be obtained through the static methods on the Keyboard class, such as IsKeyUp and GetKeyStates. The Keyboard class reports the current state of the keyboard.

This example shows how to detect when the Enter key is pressed on the keyboard.

This example consists of a Extensible Application Markup Language (XAML) file and a code-behind file.

When the user presses the Enter key in the TextBox, the input in the text box appears in another area of the user interface (UI).

The following XAML creates the user interface, which consists of a StackPanel, a TextBlock, and a TextBox.

<StackPanel>
  <TextBlock Width="300" Height="20">
    Type some text into the TextBox and press the Enter key.
  </TextBlock>
  <TextBox Width="300" Height="30" Name="textBox1"
           KeyDown="OnKeyDownHandler"/>
  <TextBlock Width="300" Height="100" Name="textBlock1"/>
</StackPanel>

The following code behind creates the KeyDown event handler. If the key that is pressed is the Enter key, a message is displayed in the TextBlock.

private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft