Enum KeyCode
The KeyCode enumeration encodes key information from IConsoleDrivers and provides a consistent way for application code to specify keys and receive key events.
The Key class provides a higher-level abstraction, with helper methods and properties for common operations. For example, IsAlt and IsCtrl provide a convenient way to check whether the Alt or Ctrl modifier keys were pressed when a key was pressed.
[Flags]
public enum KeyCode : uint
Fields
A = 65The key code for the A key
AltMask = 2147483648When this value is set, the Key encodes the sequence Alt-KeyValue. The actual value must be extracted by removing the AltMask.
B = 66The key code for the B key
Backspace = 8Backspace key.
C = 67The key code for the C key
CharMask = 1048575Mask that indicates that the key is a unicode codepoint. Values outside this range indicate the key has shift modifiers or is a special key like function keys, arrows keys and so on.
Clear = 12The key code for the clear key.
CtrlMask = 1073741824When this value is set, the Key encodes the sequence Ctrl-KeyValue. The actual value must be extracted by removing the CtrlMask.
CursorDown = 1114151Cursor down key.
CursorLeft = 1114148Cursor left key.
CursorRight = 1114150Cursor right key.
CursorUp = 1114149Cursor up key
D = 68The key code for the D key
D0 = 48Digit 0.
D1 = 49Digit 1.
D2 = 50Digit 2.
D3 = 51Digit 3.
D4 = 52Digit 4.
D5 = 53Digit 5.
D6 = 54Digit 6.
D7 = 55Digit 7.
D8 = Backspace | D0Digit 8.
D9 = 57Digit 9.
Delete = 1114157Delete (DEL) key.
E = 69The key code for the E key
End = 1114146End key.
Enter = 13The key code for the return key.
Esc = 27The key code for the escape key.
F = 70The key code for the F key
F1 = B | DeleteF1 key.
F10 = Backspace | F2F10 key.
F11 = 1114233F11 key.
F12 = 1114234F12 key.
F13 = 1114235F13 key.
F14 = 1114236F14 key.
F15 = 1114237F15 key.
F16 = 1114238F16 key.
F17 = 1114239F17 key.
F18 = 1114240F18 key.
F19 = 1114241F19 key.
F2 = P | PageUpF2 key.
F20 = 1114242F20 key.
F21 = 1114243F21 key.
F22 = 1114244F22 key.
F23 = 1114245F23 key.
F24 = 1114246F24 key.
F3 = 1114225F3 key.
F4 = 1114226F4 key.
F5 = 1114227F5 key.
F6 = 1114228F6 key.
F7 = 1114229F7 key.
F8 = 1114230F8 key.
F9 = 1114231F9 key.
G = 71The key code for the G key
H = 72The key code for the H key
Home = 1114147Home key.
I = 73The key code for the I key
Insert = Backspace | CursorLeftInsert (INS) key.
J = 74The key code for the J key
K = 75The key code for the K key
L = 76The key code for the L key
M = 77The key code for the M key
MaxCodePoint = 1114111The maximum Unicode codepoint value. Used to encode the non-alphanumeric control keys.
N = 78The key code for the N key
Null = 0The key code representing an invalid or empty key.
O = 79The key code for the O key
P = 80The key code for the P key
PageDown = 1114145Page Down key.
PageUp = 1114144Page Up key.
PrintScreen = Backspace | HomePrint screen character key.
Q = 81The key code for the Q key
R = 82The key code for the R key
S = 83The key code for the S key
ShiftMask = 268435456When this value is set, the Key encodes the sequence Shift-KeyValue. The actual value must be extracted by removing the ShiftMask.
Space = 32The key code for the space bar key.
SpecialMask = 4293918720If the SpecialMask is set, then the value is that of the special mask, otherwise, the value is in the lower bits (as extracted by CharMask).
T = 84The key code for the T key
Tab = 9The key code for the tab key (forwards tab key).
U = 85The key code for the U key
V = 86The key code for the V key
W = 87The key code for the W key
X = Backspace | PThe key code for the X key
Y = 89The key code for the Y key
Z = 90The key code for the Z key
Remarks
Lowercase alpha keys are encoded as values between 65 and 90 corresponding to the un-shifted A to Z keys on a keyboard. Enum values are provided for these (e.g. A, B, etc.). Even though the values are the same as the ASCII values for uppercase characters, these enum values represent *lowercase*, un-shifted characters.
Numeric keys are the values between 48 and 57 corresponding to 0 to 9 (e.g. D0, D1, etc.).
The shift modifiers (ShiftMask, CtrlMask, and AltMask) can be combined (with logical or) with the other key codes to represent shifted keys. For example, the A enum value represents the un-shifted 'a' key, while ShiftMask | A represents the 'A' key (shifted 'a' key). Likewise, AltMask | A represents the 'Alt+A' key combination.
All other keys that produce a printable character are encoded as the Unicode value of the character. For example, the KeyCode for the '!' character is 33, which is the Unicode value for '!'. Likewise, `â` is 226, `Â` is 194, etc.
If the SpecialMask is set, then the value is that of the special mask, otherwise, the value is the one of the lower bits (as extracted by CharMask).