Keyboard
Description
The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port.
Note: Not every possible ASCII character, particularly the non-printing ones, can be sent with the Keyboard library.
The library supports the use of modifier keys. Modifier keys change the behavior of another key when pressed simultaneously. See here for additional information on supported keys and their use.
Compatible Hardware
HID is supported on the following boards:
Board | Supported Pins |
---|---|
Leonardo | All digital & analog pins |
Micro | All digital & analog pins |
Due | All digital & analog pins |
Zero | All digital & analog pins |
UNO R4 Minima | All digital & analog pins |
UNO R4 WiFi | All digital & analog pins |
GIGA R1 WiFi | All digital & analog pins |
Nano ESP32 | All digital & analog pins |
MKR Family | All digital & analog pins |
Notes and Warnings
These core libraries allow the 32u4 and SAMD based boards (Leonardo, Esplora, Zero, Due and MKR Family) to appear as a native Mouse and/or Keyboard to a connected computer.
A word of caution on using the Mouse and Keyboard libraries: if the Mouse or Keyboard library is constantly running, it will be difficult to program your board. Functions such as
Mouse.move()
and Keyboard.print()
will move your cursor or send keystrokes to a connected computer and should only be called when you are ready to handle them. It is recommended to use a control system to turn this functionality on, like a physical switch or only responding to specific input you can control. Refer to the Mouse and Keyboard examples for some ways to handle this.When using the Mouse or Keyboard library, it may be best to test your output first using Serial.print(). This way, you can be sure you know what values are being reported.
Functions
- Keyboard.begin()
- Keyboard.end()
- Keyboard.press()
- Keyboard.print()
- Keyboard.println()
- Keyboard.release()
- Keyboard.releaseAll()
- Keyboard.write()
See also
- KeyboardAndMouseControl: Demonstrates the Mouse and Keyboard commands in one program.
- KeyboardMessage: Sends a text string when a button is pressed.
- KeyboardLogout: Logs out the current user with key commands
- KeyboardSerial: Reads a byte from the serial port, and sends back a keystroke.
- KeyboardReprogram^: Opens a new window in the Arduino IDE and reprograms the board with a simple blink program
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.