Key Codes for Coded UI Tests

A colleague of mine asked me this week how he can emulate special keys in Coded UI Tests. I knew that I wrote that in my book but actually did not find the official reference in the MSDN. That’s why I will provide it here again.

The Keyboard class provides different methods with which you can send texts or key codes to the UI element currently selected. Some of these methods also allow the use of modifier keys like Ctrl or Alt.

Keyboard.SendKeys(“Message{ENTER}”);
Keyboard.SendKeys(“{F4}”, ModifierKeys.Alt);

All special keys are shown in the following list. They are usually surrounded by curly braces and can be part of any string (see also the example above).

Key Code
Backspace {BACKSPACE}, {BS} or {BKSP}
Pause {BREAK}
Capslock {CAPSLOCK}
Delete {DELETE} or {DEL}
End {END}
Return {ENTER} or ~
Esc {ESC}
Help {HELP}
Pos1 {HOME}
Insert {INSERT} or {INS}
Numlock {NUMLOCK}
Page Down {PGDN}
Page Up {PGUP}
Print {PRTSC}
Scrollock {SCROLLLOCK}
Tab {TAB}
F1… {F1}
Cursor up {UP}
Cursor down {DOWN}
Cursor left {LEFT}
Cursor right {RIGHT}
Addition (num block) {ADD}
Subtraction (num block) {SUBTRACT}
Multiplication (num block) {MULTIPLY}
Division (num block)) {DIVIDE}