Create an USB fake keyboard using HID class

Gerhard56
Posts: 1
Joined: Sat Apr 18, 2026 7:24 pm

Create an USB fake keyboard using HID class

Postby Gerhard56 » Sat Apr 18, 2026 7:43 pm

Hello,
I try to create a fake USB keyboard using HID class to control a recorder (PreMix by Sound Systems). My ESP32s3 DevKit1 works fine with my laptop but isn't registrated by the MixPre.
I used USBDeview to find out whats going on and I found some strange behaviour:

I use the socket labeld 'USB' at the DevKit and I disabled all USB functionality in the Arduino IDE, only USB OTG is active. After plugging in I see three new devices in USBDeview, a JTAG, a Serial and a keyboard. After some secondes only the keyboard is remains.

My guess: When I plug into MixPre, the same thing happens, but the firmware gets totally disturbed and just ignodred my stuff.

Is there any way to prevent JTAG and Serial to show up? I have a second USB connector for that stuff and use it for programming and for the serial monitor, no need to have this doubled.

I start developing this USB sketch using the example 'Keyboard Message.

Thanks a lot for helping.

With best regards

Gerhard

RandomInternetGuy
Posts: 84
Joined: Fri Aug 11, 2023 4:56 am

Re: Create an USB fake keyboard using HID class

Postby RandomInternetGuy » Thu Jun 25, 2026 5:08 pm

> I have a second USB connector for [ JTAG and serial ].

It's unlikely you actually do. Few boards bring JTAG out to second USB connectors, as it would require adding a USB/JTAG bridge and a ton of software to manage it. It's possible/probable that you have a second port that's connected to a USB/Serial bridge that's external to the S3. That's a common configuration for S3 dev boards. But to the Espressif port, that's not a USB port at all. The external UART (a CP2103 or CH340-like substance) is connected to the serial pins that are connected to the UART peripheral internally. The two ports are completely different.


As for host devices being confused by hot plug USB devices coming and going, well, that would be a bug they need to fix because that's just how USB works.

So your question seems to be about USB Serial/JTAG Controller Console
and there is a documented way to disable the JTAG/Serial system].

When you do this, you lose the ability to reset and start uploads from that port because it no longer pretends to be a serial port to respond to wiggling the control signals to yank a reset.

I think I've seen a runtime disable to disable this when the chip is running, but it tends to make host stacks even grumpier if you yank the device away once they've started talking to them (though, by specification, they must still cope...) than if you just stop the devices from enumerating completely, such as by turning them off in menuconfig.

horace99
Posts: 36
Joined: Mon Oct 14, 2024 10:38 am

Re: Create an USB fake keyboard using HID class

Postby horace99 » Fri Jun 26, 2026 9:17 am

sounds like you require a USB OTG keyboard device

using a ESP32-S3-DevKitC-1 which has two USB connectors - labelled COM (for programming and serial monitor) and USB (for USB OTG device and host)
I ran the following program

Code: Select all

// ESP32-S3-DevKit-1 USB Device Keyboard test

// File>Examples>USB>Keyboard>KeyboardSerial

// Tools>Board to ESP32-S3-USB-OTG  
//     Upload Mode "UART0/Hardware CDC"
//     USB Mode "USB-OTG"

// when I run it and enter on the Serial monitor "aaaa" it echoes back "bbbb"

/*
  Keyboard test

  Reads a byte from the serial port, sends a keystroke back.
  The sent keystroke is one higher than what's received, e.g. if you send a,
  you get b, send A you get B, and so forth.

  The circuit:
  - none

  created 21 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardSerial
*/
#include <Arduino.h>
#ifndef ARDUINO_USB_MODE
#error This ESP32 SoC has no Native USB interface
#elif ARDUINO_USB_MODE == 1
#warning This sketch should be used when USB is in OTG mode
void setup() {}
void loop() {}
#else

#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

void setup() {
  // open the serial port:
  Serial.begin(115200);
  // initialize control over the keyboard:
  Keyboard.begin();
  USB.begin();
}

void loop() {
  // check for incoming serial data:
  if (Serial.available() > 0) {
    // read incoming serial data:
    char inChar = Serial.read();
    // Type the next ASCII value from what you received:
    Keyboard.write(inChar + 1);
  }
}
#endif /* ARDUINO_USB_MODE */

plugged the connector labelled USB into a PC USB and it created a virtual keyboard - text entered on the ESP32S3 serial monitor was transmitted to PC and appeared on the PC display
if your ESP32S3 module does not have a second USB connector you can connect to the OTG port via to GPIO20 USB_D+ and GPIO21 USB_D-

Who is online

Users browsing this forum: No registered users and 3 guests