Source: https://mokxi.com/libraries/mouse
Updated: 2026-11-02

Libraries / Communication
Arduino library · Communication

# The Arduino Mouse library: move the pointer from a board

Mouse.h lets a board with native USB act as a mouse. Like the Keyboard library it needs an ATmega32U4 board (Leonardo, Micro, Pro Micro) or another board whose chip is a USB device; an Uno cannot do it. The computer sees an ordinary three-button mouse with a scroll wheel.

Open the example in the editor See the calls

Built in on Mokxi: #include <Mouse.h> and it builds, with nothing to install. Free, and no account needed.

## What Mouse does

A mouse reports relative motion, not a position. Mouse.move(x, y) means "move this many counts from wherever the pointer is now", each from -128 to 127, and the computer’s pointer speed setting decides how far that is on screen. To steer it with a thumb joystick, read the two axes, subtract the center reading, scale it down to a few counts, and send that every 10 ms or so.

Buttons are held or tapped: click() is a quick press and release, while press() and release() let a sketch drag. A stray mouse that never stops moving makes a computer very hard to use, so keep an on and off switch in every sketch while you develop.

Library Manager name | Mouse

Author | Arduino

Include | #include <Mouse.h>

Boards | Arduino Leonardo, SparkFun Pro Micro, Arduino Micro

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on Arduino Leonardo, SparkFun Pro Micro, Arduino Micro.

In Mokxi it is built in: #include <Mouse.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board it comes with the board package (Arduino), so the Arduino IDE has it as soon as the board is installed: there is nothing to add from the Library Manager.

Arduino Leonardo · SparkFun Pro Micro · Arduino Micro

## The calls you will use

In the order a sketch meets them.

### Mouse.begin()

Starts acting as a mouse. Call once in setup().

### Mouse.move(xDistance, yDistance, wheel)

Moves the pointer by that many counts, each from -128 to 127. The third number scrolls the wheel; leave it out for 0.

### Mouse.click(MOUSE_LEFT)

Presses and releases a button. MOUSE_RIGHT and MOUSE_MIDDLE are the others.

### Mouse.press(MOUSE_LEFT)

Holds a button down, for dragging, until release() is called.

### Mouse.release(MOUSE_LEFT)

Lets the held button go.

### Mouse.isPressed(MOUSE_LEFT)

True while the sketch is holding that button, handy to avoid sending the same press twice.

### Mouse.end()

Stops sending mouse reports.

## Example: Key matrix numpad

On the SparkFun Pro Micro. It runs in the browser exactly as printed.

sketch.ino · SparkFun Pro Micro

The sketch is cut short here; the editor has every line of it.

Open it in the editor, wired and ready to run · Key matrix numpad: the project page

## Common errors and how to fix them

### The pointer drifts on its own with the joystick at rest

A centered joystick rarely reads exactly 512. Subtract its real resting reading taken at start-up, and ignore small values (a dead zone of 10 or 20 counts) before calling move().

### The pointer flies across the screen and the computer is unusable

The sketch sends large moves too often. Divide the readings down, add a short delay between reports, and guard the whole thing with a switch read by digitalRead() so you can turn the mouse off.

### 'Mouse' not found, or Mouse.h does not build

Include Mouse.h at the top of the sketch and pick a board with native USB such as a Leonardo, Micro or Pro Micro. An Uno or Nano cannot act as a mouse.

## Keep going

### Learn

- Arduino Joystick Module: Wiring, Code, Live Demo
- Arduino Leonardo Pinout: I2C, SPI on ICSP, A6-A11

### More communication libraries

- OneWire
- TinyGPS
- TinyGPSPlus
- MFRC522
- SoftwareSerial
- AltSoftSerial
- i2cdetect
- Keyboard

Every built-in library · Open the editor

## Try Mouse without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
