• Stars
    star
    2,350
  • Rank 19,444 (Top 0.4 %)
  • Language
    C++
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)

ESP32 BLE Keyboard library

This library allows you to make the ESP32 act as a Bluetooth Keyboard and control what it does.
You might also be interested in:

Features

  • Send key strokes
  • Send text
  • Press/release individual keys
  • Media keys are supported
  • Read Numlock/Capslock/Scrolllock state
  • Set battery level (basically works, but doesn't show up in Android's status bar)
  • Compatible with Android
  • Compatible with Windows
  • Compatible with Linux
  • Compatible with MacOS X (not stable, some people have issues, doesn't work with old devices)
  • Compatible with iOS (not stable, some people have issues, doesn't work with old devices)

Installation

Example

/**
 * This example turns the ESP32 into a Bluetooth LE keyboard that writes the words, presses Enter, presses a media key and then Ctrl+Alt+Delete
 */
#include <BleKeyboard.h>

BleKeyboard bleKeyboard;

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

void loop() {
  if(bleKeyboard.isConnected()) {
    Serial.println("Sending 'Hello world'...");
    bleKeyboard.print("Hello world");

    delay(1000);

    Serial.println("Sending Enter key...");
    bleKeyboard.write(KEY_RETURN);

    delay(1000);

    Serial.println("Sending Play/Pause media key...");
    bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);

    delay(1000);
    
   //
   // Below is an example of pressing multiple keyboard modifiers 
   // which by default is commented out. 
   // 
   /* Serial.println("Sending Ctrl+Alt+Delete...");
    bleKeyboard.press(KEY_LEFT_CTRL);
    bleKeyboard.press(KEY_LEFT_ALT);
    bleKeyboard.press(KEY_DELETE);
    delay(100);
    bleKeyboard.releaseAll();
    */

  }
  Serial.println("Waiting 5 seconds...");
  delay(5000);
}

API docs

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

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

#include <BleKeyboard.h>
BleKeyboard bleKeyboard;

In addition to that you can send media keys (which is not possible with the USB keyboard library). Supported are the following:

  • KEY_MEDIA_NEXT_TRACK
  • KEY_MEDIA_PREVIOUS_TRACK
  • KEY_MEDIA_STOP
  • KEY_MEDIA_PLAY_PAUSE
  • KEY_MEDIA_MUTE
  • KEY_MEDIA_VOLUME_UP
  • KEY_MEDIA_VOLUME_DOWN
  • KEY_MEDIA_WWW_HOME
  • KEY_MEDIA_LOCAL_MACHINE_BROWSER // Opens "My Computer" on Windows
  • KEY_MEDIA_CALCULATOR
  • KEY_MEDIA_WWW_BOOKMARKS
  • KEY_MEDIA_WWW_SEARCH
  • KEY_MEDIA_WWW_STOP
  • KEY_MEDIA_WWW_BACK
  • KEY_MEDIA_CONSUMER_CONTROL_CONFIGURATION // Media Selection
  • KEY_MEDIA_EMAIL_READER

There is also Bluetooth specific information that you can set (optional): Instead of BleKeyboard bleKeyboard; you can do BleKeyboard bleKeyboard("Bluetooth Device Name", "Bluetooth Device Manufacturer", 100);. (Max lenght is 15 characters, anything beyond that will be truncated.)
The third parameter is the initial battery level of your device. To adjust the battery level later on you can simply call e.g. bleKeyboard.setBatteryLevel(50) (set battery level to 50%).
By default the battery level will be set to 100%, the device name will be ESP32 Bluetooth Keyboard and the manufacturer will be Espressif.
There is also a setDelay method to set a delay between each key event. E.g. bleKeyboard.setDelay(10) (10 milliseconds). The default is 8.
This feature is meant to compensate for some applications and devices that can't handle fast input and will skip letters if too many keys are sent in a small time frame.

NimBLE-Mode

The NimBLE mode enables a significant saving of RAM and FLASH memory.

Comparison (SendKeyStrokes.ino at compile-time)

Standard

RAM:   [=         ]   9.3% (used 30548 bytes from 327680 bytes)
Flash: [========  ]  75.8% (used 994120 bytes from 1310720 bytes)

NimBLE mode

RAM:   [=         ]   8.3% (used 27180 bytes from 327680 bytes)
Flash: [====      ]  44.2% (used 579158 bytes from 1310720 bytes)

Comparison (SendKeyStrokes.ino at run-time)

Standard NimBLE mode difference
ESP.getHeapSize() 296.804 321.252 + 24.448
ESP.getFreeHeap() 143.572 260.764 + 117.192
ESP.getSketchSize() 994.224 579.264 - 414.960

How to activate NimBLE mode?

ArduinoIDE:

Uncomment the first line in BleKeyboard.h

#define USE_NIMBLE

PlatformIO:

Change your platformio.ini to the following settings

lib_deps = 
  NimBLE-Arduino

build_flags = 
  -D USE_NIMBLE

Credits

Credits to chegewara and the authors of the USB keyboard library as this project is heavily based on their work!
Also, credits to duke2421 who helped a lot with testing, debugging and fixing the device descriptor! And credits to sivar2311 for adding NimBLE support, greatly reducing the memory footprint, fixing advertising issues and for adding the setDelay method.

More Repositories

1

ESP32-BLE-Mouse

Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
C++
709
star
2

Memory-Hacking-Class

Easy-to-use class to read and modify other processes memory.
C++
206
star
3

MobilePassThrough

Make GPU passthrough on notebooks easy and accessible!
Shell
171
star
4

alexa-jammer

Jamming the Wifi connection and microphones of all Amazon Echo and Google Home devices surrounding you
C++
75
star
5

android-svc

Easy to use Android service wrapper
Shell
71
star
6

Termux-DeepSpeech

Open source offline speech recognition for Android using Mozilla's DeepSpeech in Termux
Shell
67
star
7

DynamicQuillTools

DynamicQuillTools is a library that allows you to dynamically add or remove new custom elements to/from a Quill Editor's toolbar. For instance a button or a drop down menu.
JavaScript
47
star
8

GPU-pass-through-compatibility-check

Automatically set up a Linux system for PCI pass-through and check if it is compatible
Shell
44
star
9

tvoip

Terminal-based P2P VoIP application (TeamSpeak-/Skype-like voice chatting over LAN or Internet)
JavaScript
38
star
10

SuperParticles

Amazing CPU-friendly particle network animations
JavaScript
38
star
11

WhoLockedMe

Shows which process is locking which files/folders
AutoHotkey
35
star
12

docker-esp-sdk

Executable docker image to easily compile and flash for the ESP32 and ESP8266
Shell
34
star
13

LedStripSimulator

Simulates an LED strip and allows very NeoPixel-like access
HTML
29
star
14

chord-collection

Simple collection of guitar chords in a javascript-friendly object and in json.
29
star
15

Electric-Unicycle-Interface

Arduino library to interface electric unicycles (e.g. read speed and temperature or change unicycle's settings) via Serial or Bluetooth
C++
20
star
16

NodeMCU-Express

HTTP Web Server library for ESP8266 modules that run the NodeMCU firmware. (Acts like express.js from node.js, but with Lua instead of JavaScript.)
Lua
19
star
17

Chord-Draw

Draw guitar chord diagrams for all variations of any chord and also display finger positions etc.
HTML
19
star
18

Long-Range-Arduino-Doorbell

Cheap, reliable and efficient long-range wireless doorbell
C++
11
star
19

DellBiosUnpackerPOC

Script that unpacks a Dell XPS BIOS so that VBiosFinder can extract the vBIOS ROMs from it
Ruby
10
star
20

Beats4Wled

Sync Spotify playback with WLED for animations based on actual beat detection!
JavaScript
9
star
21

CreateNewFileMacro

Add a shortcut to Windows to create a new file just like Ctrl+Shift+N creates a new folder in the current window
AutoHotkey
8
star
22

WLED-Fireworks-Sound-Effect-Companion

Add real time sound effects to your WLED firework animations
JavaScript
8
star
23

DHL-Open-Source-Push-Notifications

Push Notifications for DHL Tracking on Linux, Android and Mac OS and anything that runs Bash really...
Shell
7
star
24

Guitarix-Looper

Control the Guitarix Looper using an Arduino
C++
7
star
25

node-browser-audio-stream-test

VoIP between a browser and a Node.js server (voice chatting)
JavaScript
7
star
26

SMB-AutoMount

Mounts all samba (SMB) shares that are in your network. Fully automated. (Tested on Ubuntu 16.04)
Shell
6
star
27

ScaleToggle

Adds a toggle to change the display scaling of the primary monitor between 100% and 200% (requires python3)
Python
5
star
28

Easy-OpenVPN-Server

Set up your own OpenVPN Server with one click
Shell
4
star
29

jguitar-parser

JavaScript
4
star
30

Beautifier

Beautifies HTML/Javascript/Json/Command Line output/Bash output and more
AutoHotkey
3
star
31

raspi-wifi-config

Bash script to configure the WiFi of a Raspberry Pi (e.g. auto-connect to a WiFi AP and host a WiFi AP)
Shell
3
star
32

QuickFileSearch

Simple and quick file searcher
AutoHotkey
3
star
33

getLyricsFromGoogle

Simple lua script to get lyrics for a song directly from google
Lua
3
star
34

crack-captcha-poc

Proof of concept showing how easy it is to crack simple captchas using Tesseract.js
JavaScript
3
star
35

ungoogled-chromium

temporary repo for gitlab testing
Python
2
star
36

modify-windows-iso

Edit Windows ISO files on Linux
Shell
2
star
37

Responding-Websockets

Request/response implementation for WebSockets (client side)
JavaScript
2
star
38

LAN-of-Things-standard

Open standard for LAN of things
HTML
2
star
39

NodeMCU-Tetris

A Tetris-like game written in Lua for NodeMCU to run on a ESP8266
Lua
2
star
40

WinMover

Move windows between screens
AutoHotkey
2
star
41

ArduinoPowerOutageEvent

Run a batch script on power outage (Requires UPS and Arduino)
C
2
star
42

espusb-api

Client library to access the espusb api (for use in the web interface)
JavaScript
2
star
43

git-tools

Some helper tools to follow certain commit-message - and branch-naming conventions
Shell
2
star
44

CPU-Simulator

Visualizes/animates the dataflow between RAM and CPU components while running a short assembly program of your choice
AutoHotkey
2
star
45

HTML5-GUI-Crazyness-Example

Animated 3D-cube GUI with HTML5
AutoHotkey
2
star
46

LedStripController

RGB LED Strip controller using BS170 MOSFETs and an Arduino
Arduino
2
star
47

MultiTrackExport

Audacity Plugin that automatically exports all selected tracks as wav files
Common Lisp
2
star
48

NodeMCU-JSON

JSON parser for NodeMCU - Parses gigantic JSON strings without any memory issues.
Lua
1
star
49

StorageUnitConverter

Convert storage units (bytes, bits, kilobytes, kibibytes, kilobits, kibibits, mebibytes, megabytes, ...........................)
AutoHotkey
1
star
50

BootloaderOS

Hello world in assembly from scratch as bootloader...
1
star
51

hollywood-docker

A hollywood Docker image that actually works and exits properly
Dockerfile
1
star
52

AsciiLookup

AutoHotkey
1
star
53

TetrisServer

Just a test
Lua
1
star
54

gpu-passthrough.com

HTML
1
star
55

subscriptions-extractor

Extract subscriptions from NewPipe and Skytube backups in youtube's xml format
Shell
1
star
56

BoringPhpTest

Stuff
PHP
1
star
57

Tasmota-IR-Code-Converter

Covnert Pronto to Tasmota IR codes
HTML
1
star
58

LedMatrix

LED Matrix library for the NodeMCU firmware. Written in Lua. Works with WS2812, WS2812b, APA104, SK6812 and possibly more
Lua
1
star
59

ungoogled-chromium-build-environment

Docker build environment (Debian Stretch based) for ungoogled-chromium
1
star
60

NodeMCU-HttpServer

Extremely lightweight HTTP server written in Lua for ESP8266 modules running the NodeMCU firmware.
1
star
61

AutoHotkey-CWebView

Shell.Explorer WebBrowser control wrapper class
AutoHotkey
1
star