Hello, following the request to implement USB emulation for a keyboard, I have developed support for keyboard and mouse emulation on the ESP32-S3. It is now possible to type entire texts, press buttons, move the mouse on the screen, and click the mouse buttons.
To use it, connect the module to the USB port labeled USB (not the COM port), and then execute the command USB.START. This will initialize the USB emulation for both keyboard and mouse functionalities, allowing you to interact with your device seamlessly.
You should hear the classic sound in Windows when USB devices are recognized.
This sound indicates that the system has successfully detected the connected devices.
Then you can use any command like :
USB.TYPETEXT "OK"
or
USB.MOUSEMOVE 100,100
Take care that you can easily lose control of the PC with the command USB.KEYPRESS, as the key will remain pressed until the command USB.KEYRELEASE is executed. This can result in your screen being filled with repeated characters from the key that is pressed.
If the text "typed" is not correct, this probably means that you need to set up the keymap for your specific keyboard language.
I've implemented support for specific keyboards using a hex string that can be used with the command
Code: [Local Link Removed for Guests]
USB.START keymap$
as a little example, you can test this code :
Code: [Local Link Removed for Guests]
USB.START
pause 1000
px = 200 : py = 0
for z = 0 to 2*pi+0.001 step pi/360
x = cos(z) * 200
y = sin(z) * 200
usb.mousemove x-px, y-py
px = x : py = y
pause 1
next z
for z = 0 to 15
usb.typetext chr$(&hB3) ' TAB
pause 500
next z
usb.mousemove 10, 127
usb.mousemove 10, 127
usb.mousemove 10, 127
usb.mousemove 10, 127
usb.mouseclick 1
usb.typetext "USB OK " + str$(rnd())
I'm releasing this under the reference 1.70.51 to identify it as a beta version and contains "OTG" inside the version name.
It can be installed using the flasher website.
I'll release a version for the ESP32-S3 GEEK very soon (need some extra testing)
This is a preliminary version, so there may be some bugs present. I look forward to your feedback.
USB HID Command Documentation
USB.START [keymap$]
- Description: Initializes the USB system and keyboard emulation. If the additional parameter is provided, it sets up a custom key mapping.
- It is Mandatory to use this command before using the others
- Input Arguments:
- keymap$: A string containing hex values representing key mappings (if not at the end of line). If not specified the default keyboard mapping is used (EN_US).
- Note: this command can be used again for changing the keyboard mapping
- Description: Simulates typing a string of text.
- Input Arguments:
- text$: A string representing the text to be typed.
- Description: Simulates pressing and holding down a specific key.
- Input Arguments:
- keycode: A numerical value representing the key code of the key to be pressed.
- Description: Simulates releasing a specific key.
- Input Arguments:
- keycode: A numerical value representing the key code of the key to be released.
- Description: Simulates releasing all currently pressed keys.
- Input Arguments: None.
- Description: Simulates moving the mouse cursor by specified distances and optionally adjusts scrolling and panning.
- Input Arguments:
- width: A numerical value indicating horizontal movement.
- height: A numerical value indicating vertical movement.
- wheel (optional): A numerical value for wheel movement (scrolling). Defaults to zero if not provided.
- pan (optional): A numerical value for panning. Defaults to zero if not provided.
- Note: the value of these arguments is limited between -127 and +127
- Description: Simulates clicking a mouse button.
- Input Arguments:
- button: A numerical value representing the mouse button to click (e.g., left or right).
- Description: Simulates pressing and holding down a mouse button.
- Input Arguments:
- button: A numerical value representing the mouse button to press.
- Description: Simulates releasing a mouse button.
- Input Arguments:
- button: A numerical value representing the mouse button to release.
- 1: Represents the left button of the mouse, commonly used for selection and clicking.
- 2: Represents the right button of the mouse, often used for context menus.
- 4: Represents the middle button (or scroll wheel) of the mouse, typically used for scrolling or additional functions.
- 8: Represents a button that typically navigates back in web browsers or file explorers.
- 16: Represents a button that typically navigates forward in web browsers or file explorers.
- 31: Represents all mouse buttons being pressed simultaneously.
Code: [Local Link Removed for Guests]
EN_US$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9EB4A0A1A2A434A6A7A5AE362D3738271E1F20212223242526B333B62EB7B89F8485868788898A8B8C8D8E8F909192939495969798999A9B9C9D2F3130A3AD350405060708090A0B0C0D0E0F101112131415161718191A1B1C1DAFB1B0B500"
FR_FR$ = "00000000000000002A2B280000000000000000000000000000000000000000002C38206030B41E21222D31AE1023B6B7A79E9FA0A1A2A3A4A5A63736322EB290679485868788898A8B8C8D8E8FB39192938495969798999D9B9C9A62656D6625641405060708090A0B0C0D0E0F331112130415161718191D1B1C1A61636E5F00"
IT_IT$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9F74A1A2A32DA5A6B030363837A4271E1F20212223242526B7B632A7B2AD738485868788898A8B8C8D8E8F909192939495969798999A9B9C9D6F3570AEB8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D00B5000000"
DE_DE$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9F31A1A2A3B1A5A6B030363837A4271E1F20212223242526B7B632A7B2AD548485868788898A8B8C8D8E8F909192939495969798999A9B9D9C656D6600B8000405060708090A0B0C0D0E0F101112131415161718191A1B1D1C6472677000"
ES_ES$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9F74A1A2A32DA5A6B030363837A4271E1F20212223242526B7B632A7B2AD738485868788898A8B8C8D8E8F909192939495969798999A9B9C9D6F3570AEB8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D00B5000000"
PT_BR$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9F20A1A2A3B1A5A6B030363837A4271E1F20212223242526B7B632A7B2AD548485868788898A8B8C8D8E8F909192939495969798999A9B9D9C656D6600B8000405060708090A0B0C0D0E0F101112131415161718191A1B1D1C6472677000"
PT_PT$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9FA0A1A2A32DA5A6AF2F363837A4271E1F20212223242526B7B632A7B2AD5F8485868788898A8B8C8D8E8F909192939495969798999A9B9C9D65356600B8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D64B5670000"
SV_SE$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9FA061A2A331A5A6B12D363837A4271E1F20212223242526B7B632A7B2AD5F8485868788898A8B8C8D8E8F909192939495969798999A9B9C9D656D6600B8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D6472670000"
DA_DK$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9FA061A2A331A5A6B12D363837A4271E1F20212223242526B7B632A7B2AD5F8485868788898A8B8C8D8E8F909192939495969798999A9B9C9D65726600B8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D646E670000"
HU_HU$ = "00000000000000002A2B280000000000000000000000000000000000000000002CA19F5B73A2469EA5A678A0363837A3351E1F20212223242526B77672A45DB6598485868788898A8B8C8D8E8F909192939495969798999A9B9D9C49544A60B8640405060708090A0B0C0D0E0F101112131415161718191A1B1D1C455A515E00"
Code: [Local Link Removed for Guests]
IT_IT$ = "00000000000000002A2B280000000000000000000000000000000000000000002C9E9F74A1A2A32DA5A6B030363837A4271E1F20212223242526B7B632A7B2AD738485868788898A8B8C8D8E8F909192939495969798999A9B9C9D6F3570AEB8000405060708090A0B0C0D0E0F101112131415161718191A1B1C1D00B5000000"
USB.START IT_IT$
KEY_LEFT_CTRL &h80
KEY_LEFT_SHIFT &h81
KEY_LEFT_ALT &h82
KEY_LEFT_GUI &h83
KEY_RIGHT_CTRL &h84
KEY_RIGHT_SHIFT &h85
KEY_RIGHT_ALT &h86
KEY_RIGHT_GUI &h87
KEY_UP_ARROW &hDA
KEY_DOWN_ARROW &hD9
KEY_LEFT_ARROW &hD8
KEY_RIGHT_ARROW &hD7
KEY_BACKSPACE &hB2
KEY_TAB &hB3
KEY_RETURN &hB0
KEY_ESC &hB1
KEY_INSERT &hD1
KEY_DELETE &hD4
KEY_PAGE_UP &hD3
KEY_PAGE_DOWN &hD6
KEY_HOME &hD2
KEY_END &hD5
KEY_CAPS_LOCK &hC1
KEY_F1 &hC2
KEY_F2 &hC3
KEY_F3 &hC4
KEY_F4 &hC5
KEY_F5 &hC6
KEY_F6 &hC7
KEY_F7 &hC8
KEY_F8 &hC9
KEY_F9 &hCA
KEY_F10 &hCB
KEY_F11 &hCC
KEY_F12 &hCD
KEY_F13 &hF0
KEY_F14 &hF1
KEY_F15 &hF2
KEY_F16 &hF3
KEY_F17 &hF4
KEY_F18 &hF5
KEY_F19 &hF6
KEY_F20 &hF7
KEY_F21 &hF8
KEY_F22 &hF9
KEY_F23 &hFA
KEY_F24 &hFB