clavier-auto-tape.ino

Arduino Leonardo — Board Fiche · File : clavier-auto-tape.ino · Language : Arduino · Use case : Envoyer du texte au clavier : l'Arduino se fait passer pour un clavier USB

Because the 32U4 embeds the USB controller, the Keyboard library enumerates a real HID keyboard: the computer receives keystrokes as if typed. Ideal for macros or WPS code entry.

Hardware required

An Arduino Leonardo (ATmega32U4, 16 MHz, 5 V) with native USB: the board can pose as a keyboard or a mouse. None.

Wiring

A plain USB cable to the computer.

How it works

Keyboard.begin activates the HID device; println sends the keystrokes one by one. The initial delay avoids typing before USB enumeration finishes. In the Arduino IDE, select « Arduino Leonardo » and the port, then Upload. Caution: a sketch that sleeps too fast can « lose » the USB port; hold RESET for 12 s to wipe the bootloader.

Going further

Chain a button to trigger the macro on demand, or read a serial barcode and retype it.

clavier-auto-tape.ino

// L'ATmega32U4 enumere un vrai clavier HID : il "tape" au clavier.
#include <Keyboard.h>

void setup() {
  Keyboard.begin();
  delay(3000);        // laisse le temps au systeme de enumerer le clavier
  Keyboard.println("Bonjour depuis mon Arduino !");
  Keyboard.write(KEY_TAB);
  delay(200);
  Keyboard.println("Ne tapez pas pendant que je travaille.");
}

void loop() {
  // Rien : la sequence s'execute une fois au demarrage.
}

← Back to the board