Source: https://mokxi.com/libraries/keyboard
Updated: 2026-11-02

Libraries / Communication
Arduino library · Communication

# The Arduino Keyboard library: a board that types

Keyboard.h turns an Arduino into a USB keyboard that the computer accepts without a driver. It only works on boards whose main chip speaks USB itself: the Leonardo, Micro and Pro Micro with the ATmega32U4, plus newer boards such as the Uno R4 and the SAMD and RP2040 ones. An Uno or Nano has a separate USB-to-serial chip and cannot do it.

Open the example in the editor See the calls

Built in on Mokxi: #include <Keyboard.h> and it builds, with nothing to install. Free, and no account needed.

## What Keyboard does

It can type text a key at a time with print(), or hold keys down with press() and let them go with release() or releaseAll(), which is how hotkeys like Ctrl+C or Alt+Tab are sent. Up to six ordinary keys plus the modifiers can be held at once. Text is typed for a US keyboard layout, so on another layout some symbols come out as different characters.

People use it for macro pads, stream decks, foot pedals and test rigs. Because the board starts typing as soon as it is plugged in, always give a new sketch a way to stay quiet, such as a switch it checks before sending anything.

Library Manager name | Keyboard

Author | Arduino

Include | #include <Keyboard.h>

Boards | Arduino Leonardo, SparkFun Pro Micro, Arduino Micro

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on Arduino Leonardo, SparkFun Pro Micro, Arduino Micro.

In Mokxi it is built in: #include <Keyboard.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board it comes with the board package (Arduino), so the Arduino IDE has it as soon as the board is installed: there is nothing to add from the Library Manager.

Arduino Leonardo · SparkFun Pro Micro · Arduino Micro

## The calls you will use

In the order a sketch meets them.

### Keyboard.begin()

Starts acting as a keyboard. Call it once in setup().

### Keyboard.print("Hello")

Types the text one key at a time. println() adds an Enter at the end.

### Keyboard.press(KEY_LEFT_CTRL)

Holds a key down until it is released. Combine several presses for a shortcut.

### Keyboard.release(KEY_LEFT_SHIFT)

Lets go of one held key.

### Keyboard.releaseAll()

Lets go of every key, the safe way to end any shortcut.

### Keyboard.write(KEY_RETURN)

Presses and releases one key, such as KEY_RETURN, KEY_TAB or KEY_F5.

### Keyboard.end()

Stops sending keys; the board stays connected.

## Example: Stream deck on a Pro Micro

On the SparkFun Pro Micro. It runs in the browser exactly as printed.

sketch.ino · SparkFun Pro Micro

Open it in the editor, wired and ready to run · Stream deck on a Pro Micro: the project page

## Common errors and how to fix them

### 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

Current Arduino cores no longer include the keyboard library automatically. Add #include <Keyboard.h> at the top, and make sure the board selected is a Leonardo, Micro or Pro Micro.

### Keyboard.h fails to build on an Uno or Nano

Those boards cannot be USB devices: their USB is a separate serial chip. Use a board with an ATmega32U4 (Leonardo, Micro, Pro Micro) or another board with native USB.

### The board types nonstop and is hard to reprogram

Double-tap reset on a Pro Micro or hold reset on a Leonardo while the upload starts, and upload a sketch that only types when a button is pressed or a switch is on.

### Some symbols come out wrong, such as @ or quotes

The library types for a US layout. On another keyboard layout, set the computer to US for testing, or send the key codes your layout needs with press().

## Projects that use Keyboard

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Key matrix numpad Twelve switches in a 4 x 3 matrix with a diode on every key, three layers, an encoder and per-key RGB on a Pro Micro, typed as a USB keyboard.

## Keep going

### Learn

- Prototype Your Keyboard Matrix Before You Solder
- Arduino Leonardo Pinout: I2C, SPI on ICSP, A6-A11

### More communication libraries

- OneWire
- TinyGPS
- TinyGPSPlus
- MFRC522
- SoftwareSerial
- AltSoftSerial
- i2cdetect
- Mouse

Every built-in library · Open the editor

## Try Keyboard without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
