Skip to content
Bluetooth LE Mouse library for the ESP32
C++
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
BleConnectionStatus.cpp
BleConnectionStatus.h Make the BleMouse interface almost identical to the Mouse interface Aug 5, 2019
BleMouse.cpp
BleMouse.h
README.md Improve documentation; Change default device info Aug 8, 2019
keywords.txt Clean up Aug 6, 2019
library.properties

README.md

ESP32 BLE Mouse library

This library allows you to make the ESP32 act as a Bluetooth Mouse and control what it does. E.g. move the mouse, scroll, make a click etc.

Features

  • Left click
  • Right click
  • Middle click
  • Back/Forwards click
  • Move mouse pointer left/right
  • Move mouse pointer up/down
  • Scroll up/down
  • Scroll left/right
  • Report optional battery level to host
  • Customize Bluetooth device name/manufacturer
  • Compatible with Android
  • Compatible with Windows
  • Compatible with Linux
  • Compatible with MacOS X (Untested)
  • Compatible with iOS (Untested)

Installation

Example

/**
 * This example turns the ESP32 into a Bluetooth LE mouse that scrolls down every 2 seconds.
 */
#include <BleMouse.h>

BleMouse bleMouse;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleMouse.begin();
}

void loop() {
  if(bleMouse.isConnected()) {
    Serial.println("Scroll Down");
    bleMouse.move(0,0,-1);
  }
  delay(2000);
}

API docs

The BleMouse interface is almost identical to the Mouse Interface, so you can use documentation right here: https://www.arduino.cc/reference/en/language/functions/usb/mouse/

Just remember that you have to use bleMouse instead of just Mouse and you need these two lines at the top of your script:

#include <BleMouse.h>
BleMouse bleMouse;

This library supports a few additional features that the Mouse library does not support at the time of writing:

  • Scrolling left/right E.g.: bleMouse.move(0,0,0,1) (Scroll left) and bleMouse.move(0,0,0,-1) (Scroll right)
  • Using the back and forward buttons E.g.: bleMouse.click(MOUSE_BACK) and bleMouse.click(MOUSE_FORWARD)

There is also Bluetooth specific information that you can use (optional):

Instead of BleMouse bleMouse; you can do BleMouse bleMouse("Bluetooth Device Name", "Bluetooth Device Manufacturer", 100);. The third parameter is the initial battery level of your device. To adjust the battery level later on you can simply call e.g. bleMouse.setBatteryLevel(50) (set battery level to 50%). By default the battery level will be set to 100%, the device name will be ESP32 Bluetooth Mouse and the manufacturer will be Espressif.

Credits

Credits to chegewara as this library is based on this piece of code that he provided.

You can’t perform that action at this time.