tobozo / ESP32-USB-Soft-Host

An Arduino wrapper to @sdima1357's usb_soft_host esp-idf example
GNU Affero General Public License v3.0
293 stars 44 forks source link

add support to read and print keystrokes. #46

Open mayur-rajput opened 1 year ago

mayur-rajput commented 1 year ago

hello, it would be more helpful if you can add support for usb keyboard to read and serial print the keystroke.

tobozo commented 1 year ago

hi,

please refer to the keyboard parser in M5Stack_Grey_USB_Test, where usbkbd.h implements a basic qwerty layout, and kbdparser.h handles the parsing events.

just copy usbkbd.h and kbdparser.h files to your sketch folder

you can keep usbkbd.h unchanged, but you will have to edit kbdparser.h (e.g. remove all tft.* statements), and replace the callback function in your sketch:

KbdRptParser Prs;

// keyboard data parser to pass to the USB driver as a callback
static void my_USB_PrintCB(uint8_t usbNum, uint8_t byte_depth, uint8_t* data, uint8_t data_len)
{
  Prs.Parse( usbNum, data_len, data );
}

if you feel like such example sketch will be helpful, feel free to submit a pull request :wink: