Description

When given a printable ASCII character as an argument, the functions Keyboard.write(), Keyboard.press() and Keyboard.release() simulate actuations on the corresponding keys. These functions can also handle ASCII characters that require pressing a key in combination with Shift or, on international keyboards, AltGr. For example:

    Keyboard.write('a');  // press and release the 'A' key
    Keyboard.write('A');  // press Shift and 'A', then release both

A typical keyboard, however, has many keys that do not match a printable ASCII character. In order to simulate those keys, the library provides a set of macros that can be passed as arguments to Keyboard.write(), Keyboard.press() and Keyboard.release(). For example, the key combination Shift+F2 can be generated by:

    Keyboard.press(KEY_LEFT_SHIFT);  // press and hold Shift
    Keyboard.press(KEY_F2);          // press and hold F2
    Keyboard.releaseAll();           // release both

Note that, in order to press multiple keys simultaneously, one has to use Keyboard.press() rather than Keyboard.write(), as the latter just “hits” the keys (it presses and immediately releases them).

The available macros are listed below.

Keyboard modifiers

These keys are meant to modify the normal action of another key when the two are pressed in combination.

KeyHexadecimal valueDecimal valueNotes
KEY_LEFT_CTRL0x80128
KEY_LEFT_SHIFT0x81129
KEY_LEFT_ALT0x82130Option (⌥) on Mac
KEY_LEFT_GUI0x83131OS logo, Command (⌘) on Mac
KEY_RIGHT_CTRL0x84132
KEY_RIGHT_SHIFT0x85133
KEY_RIGHT_ALT0x86134also AltGr, Option (⌥) on Mac
KEY_RIGHT_GUI0x87135OS logo, Command (⌘) on Mac

Special keys

These are all the keys that do not match a printable ASCII character and are not modifiers.

Within the alphanumeric cluster

KeyHexadecimal valueDecimal value
KEY_TAB0xB3179
KEY_CAPS_LOCK0xC1193
KEY_BACKSPACE0xB2178
KEY_RETURN0xB0176
KEY_MENU0xED237
KeyHexadecimal valueDecimal value
KEY_INSERT0xD1209
KEY_DELETE0xD4212
KEY_HOME0xD2210
KEY_END0xD5213
KEY_PAGE_UP0xD3211
KEY_PAGE_DOWN0xD6214
KEY_UP_ARROW0xDA218
KEY_DOWN_ARROW0xD9217
KEY_LEFT_ARROW0xD8216
KEY_RIGHT_ARROW0xD7215

Numeric keypad

KeyHexadecimal valueDecimal value
KEY_NUM_LOCK0xDB219
KEY_KP_SLASH0xDC220
KEY_KP_ASTERISK0xDD221
KEY_KP_MINUS0xDE222
KEY_KP_PLUS0xDF223
KEY_KP_ENTER0xE0224
KEY_KP_10xE1225
KEY_KP_20xE2226
KEY_KP_30xE3227
KEY_KP_40xE4228
KEY_KP_50xE5229
KEY_KP_60xE6230
KEY_KP_70xE7231
KEY_KP_80xE8232
KEY_KP_90xE9233
KEY_KP_00xEA234
KEY_KP_DOT0xEB235

Escape and function keys

The library can simulate function keys up to F24.

KeyHexadecimal valueDecimal value
KEY_ESC0xB1177
KEY_F10xC2194
KEY_F20xC3195
KEY_F30xC4196
KEY_F40xC5197
KEY_F50xC6198
KEY_F60xC7199
KEY_F70xC8200
KEY_F80xC9201
KEY_F90xCA202
KEY_F100xCB203
KEY_F110xCC204
KEY_F120xCD205
KEY_F130xF0240
KEY_F140xF1241
KEY_F150xF2242
KEY_F160xF3243
KEY_F170xF4244
KEY_F180xF5245
KEY_F190xF6246
KEY_F200xF7247
KEY_F210xF8248
KEY_F220xF9249
KEY_F230xFA250
KEY_F240xFB251

Function control keys

These are three keys that sit above the navigation cluster.

KeyHexadecimal valueDecimal valueNotes
KEY_PRINT_SCREEN0xCE206Print Screen or PrtSc / SysRq
KEY_SCROLL_LOCK0xCF207
KEY_PAUSE0xD0208Pause / Break

International keyboard layouts

Some national layouts define extra keys. For example, the Swedish and Danish layouts define KEY_A_RING as 0xB7, which is the key to the right of “P”, labeled “Å” on those layouts and “{ / [” on the US layout. In order to use those definitions, one has to include the proper Keyboard.h file. For example:

    #include <Keyboard.h>
    #include <Keyboard_sv_SE.h> // extra key definitions from Swedish layout

    void setup() {
      Keyboard.begin(KeyboardLayout_sv_SE); // use the Swedish layout
      Keyboard.write(KEY_A_RING);
    }

    void loop() {} // do-nothing loop

For the list of layout-specific key definitions, see the respective Keyboard.h file within the library sources.