breadboard
Example project · Builds & projects

Uno R4 · USB keyboard and mouse

Official Keyboard and Mouse libraries send Ctrl+Shift+A, uppercase B, mouse buttons and relative movement through the emulated USB controller. Select the board to see USB console and HID reports in the Inspector. Serial echoes each line you send. Reports stay inside Breadboard.

The Uno R4 · USB keyboard and mouse circuit as rendered by the simulator

What's on the bench

  • Arduino Uno R4
  • Battery

How it's wired

  • Battery · pos→Arduino Uno R4 · 5v
  • Battery · neg→Arduino Uno R4 · gnd

The code

This Arduino C++ sketch lives in the Code tab; sign in and press Compile & upload to build real firmware for the emulated board.

// SPDX-License-Identifier: MIT
// Official Keyboard 1.0.7 and Mouse 1.0.1 APIs; reports remain in the simulator.
#include <Keyboard.h>
#include <Mouse.h>

void setup() {
  Serial.begin(115200);
  Keyboard.begin();
  Mouse.begin();
  while (!Serial) {}
  Serial.println("public HID ready");
}

void loop() {
  while (Serial.available()) Serial.write(Serial.read());
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.press('a');
  Keyboard.release('a');
  Keyboard.releaseAll();
  Keyboard.write('B');
  Mouse.press(MOUSE_LEFT | MOUSE_RIGHT);
  Mouse.move(7, -3, 1);
  Mouse.release(MOUSE_ALL);
  Mouse.click(MOUSE_MIDDLE);
  Serial.println("public HID reports sent");
  delay(250);
}

Firmware licence

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-unor4wifi-usb-keyboard-mouse.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.

This image also links official Keyboard 1.0.7 and Mouse 1.0.1. Keyboard layout files use the GNU Lesser General Public License, version 3. The package and source bundle include the LGPL-3.0 and GPL-3.0 texts.

Related projects