Hello,
is it possible for a microcontroller like the ESP32-S3 or RP2040 to access keyboard outputs while the computer remains the host? In other words, can the microcontroller read the data sent from the keyboard without being the host, while the computer continues as the primary host? Through this, could the microcontroller, for example, control an LED or create shortcuts when a specific key on the keyboard is pressed, without affecting the keyboard's functionality for the computer?
For Windows, your concept of computer is entirely wrong. The only program that reads or writes to any PC hardware is part of the Windows operating system. Any program that you as a user runs, only gets hardware information, like the keyboard, is from the operating system program that directly reads the keyboard. Same with reading or writing a disk file. NEVER directly done. Always done by one or more level of driver programs.
The prime directive for Windows is to always keep running, no matter what a user program does.
So, the short answer is what you suggest is not possible.
I do not follow what you are asking. Check out keyboard sniffer. They go between the keyboard and computer, intercept the key info and pass it to the computer. They are also available for wireless keyboards. As @Paul_KD7HB the computer only reads and writes to what it thinks is the keyboard.
Usually done by having a microcontroller with two usb ports, one acting in “host” mode to the keyboard, and one acting in keyboard mode to the pc. Data coming from the keyboard is read, and usually passed on to the pc directly, but it could be made to have side effects as you describe.
Unfortunately, microcontrollers with two usb ports are pretty uncommon.
I suppose that it’s theoretically possible to passively sniff the keyboard data, but that would probably preclude creating macros, because the sniffing uC couldn’t suddenly start sending data without confusing everyone. I don’t know offhand of uCs that have any support for sniffing
An RP2040 can act as a USB proxy/bridge/interceptor/MITM using its PIO controller for USB host or by connecting two RP2040 with one in host mode and one in device mode. See the hid-remapper project on github.
Teensy 4.1 has USB device and host ports so it can also do this. I do not know of any example code.