#include <Keyboard.h>
void setup() {
Keyboard.begin(); // Initialize the keyboard library
delay(1000); // Wait a bit for the computer to recognize the keyboard
Keyboard.print("Hello from Arduino!"); // Types "Hello from Arduino!"
Keyboard.println(" This is a new line."); // Types and adds a newline
Keyboard.end(); // Stop keyboard emulation
}
void loop() {
// Nothing needed here for this simple example
}
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.