When used with a Leonardo or Due board, Keyboard.begin() starts emulating a keyboard connected to a computer. To end control, use Keyboard.end().
Keyboard.begin()Keyboard.begin(layout)layout: the keyboard layout to use. This parameter is optional and defaults to KeyboardLayout_en_US.
Currently, the library supports the following national keyboard layouts:
KeyboardLayout_da_DK: DenmarkKeyboardLayout_de_DE: GermanyKeyboardLayout_en_US: USAKeyboardLayout_es_ES: SpainKeyboardLayout_fr_FR: FranceKeyboardLayout_hu_HU: HungaryKeyboardLayout_it_IT: ItalyKeyboardLayout_pt_PT: PortugalKeyboardLayout_sv_SE: SwedenNothing
#include <Keyboard.h>
void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
//if the button is pressed
if (digitalRead(2) == LOW) {
//Send the message
Keyboard.print("Hello!");
}
}
Custom layouts can be created by copying and modifying an existing layout. See the instructions in the Keyboard library’s KeyboardLayout.h file.