clavier-auto-tape.ino

Arduino Micro · 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 Micro (ATmega32U4, 16 MHz, 5 V) in a breadboard-friendly format with a micro-USB connector and native USB (keyboard/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 Micro » and the port, then Upload. On Windows a .inf driver may be needed for the COM port. Since the 32U4 is the USB itself, a bad sketch can lock out reflashing (double reset).

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