Keyboard/Mouse Control with Arduino Leonardo

If you need to send keyboard/mouse commands to a computer for your project, you will need to use one of my Arduino Leonardos instead of the Arduino Unos that came with your kits. The Arduino Leonardo has a special chip that is full USB HID-compliant that acts like a keyboard and/or mouse. Once you get the basics of your project working with your Arduino Uno, I will lend you an Arduino Leonardo for your project. The information below describes how to use the necessary libraries to send commands to a computer.

 

Arduino Leonardo

The Arduino Leonardo is identical in pinout to the Arduino Uno and fairly similar in functionality. The one major difference is that we can use the "HID-Project" library to send mouse and keyboard commands to a computer.

leonardo.png  

You will need to select the dropdown in Arduino Create to compile code for an Arduino Leonardo instead of an Arduino Uno. See the image below for more info:

leonardo2.png  

HID Project Library

GitHub Repo: https://github.com/NicoHood/HID

Documentation: https://github.com/NicoHood/HID/wiki

 

Keyboard

Use Keyboard for sending keyboard commands for typical keys.

Keyboard Functions

All of the Keyboard functions are described here: https://www.arduino.cc/reference/en/language/functions/usb/keyboard/.

 

Special Keys for "Keyboard" Object.

To use these special keys on a keyboard, you must write the values as shown below.

 

Consumer

Use Consumer for sending keyboard commands for special keys like media keys (volume control, etc.). Almost identical in functionality to Keyboard, but can be used with special keys.

 

Consumer Functions

 

Special Keys for "Consumer" Object

To use these special keys on a keyboard, you must write the values as shown below.

 

Mouse

Use Mouse to send mouse commands.

Mouse Functions

All of the Mouse functions are described here: https://www.arduino.cc/reference/en/language/functions/usb/mouse/.

 

Example Code