In this tutorial you will learn how to emulate a mouse/keyboard using an Arduino UNO R4 Minima board with the Keyboard and Mouse APIs.
This feature can be used to create game controllers, keyboard extensions or other HID devices.
The goals of this tutorials are:
Human interface devices (HID) are devices designed for humans (keyboards, mice, game controllers etc.), that frequently sends data over USB to a computer. When you press a key on a keyboard, you send data to a computer, which reads it and in turn activates the corresponding key.
The UNO R4 Minima has built-in support for HID, a feature found on most modern day development boards, but not on previous UNO revisions.
To turn your board into an HID, you can use the keyboard/mouse API that is built in to the core. You can visit the documentation for this API in the language reference at:
In the section below, you will see a couple of useful examples to get you started!
To use keyboard functionalities, we need to include the library at the top of our sketch. The Keyboard class contains several methods that are useful to emulate a keyboard.
1#include <Keyboard.h>2
3Keyboard.method()
To emulate a keyboard, we can use the
press()
and releaseAll()
methods. This will emulate a keypress, as well as releasing the keypress. The following example prints a "w" every second.1#include <Keyboard.h>2
3void setup() {4 Keyboard.begin();5 delay(1000);6}7
8void loop() {9 Keyboard.press('w');10 delay(100);11 Keyboard.releaseAll();12 delay(1000); 13}
To see more examples, please refer to links below:
To use mouse functionalities, we need to include the library at the top of our sketch. The Mouse class contains several methods that are useful to emulate a mouse.
1#include <Mouse.h>2
3Mouse.method();
The following example moves both axis of mouse just slightly (10 points), back and forth.
1#include <Mouse.h>2
3void setup() {4 Mouse.begin();5 delay(1000);6}7
8void loop() {9 Mouse.move(10,10);10 delay(1000);11 Mouse.move(-10,-10);12 delay(1000); 13}
To see more examples, please refer to links below:
In this tutorial, we have demonstrated some basic HID usage with the UNO R4 Minima. To view the full API, please refer to the following APIs:
In there, you will find a detailed reference along with some good examples to get you started with HID features.