-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HID Keyboard example? #10
Comments
Keyboards and mice are very similar, with two subtle differences:
First, you'll have to modify the USB report descriptors.
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs) //1 byte
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs) //1 byte
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs) //6 bytes
0xc0 // END_COLLECTION
Next (and finally), you'll need to modify the packet that gets defined at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L240 and sent at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L257. The mouse descriptor is 4 bytes (first byte is the buttons, next byte is X, next byte is Y, next byte is mouse wheel). The keyboard descriptor is described at https://damogranlabs.com/2018/02/stm32-usb-hid-mouse-keyboard/ but basically to send an "a" you'd write "{0, 0, 4, 0, 0, 0, 0, 0}", and to send a "release key 'a'" you'd write "{0, 0, 0, 0, 0, 0, 0, 0}". |
Thank a lot xobs. Tomu is writing a's now. In line 217 |
Neat! Would you like to submit a PR with the keyboard HID example? |
Of course! Thanks. |
The easiest is to probably use the Github flow:
|
Closed by 334a395 |
Hi,
First, Tomu is really impressive.
Now, I'm looking for an example on how to make keys injection.
Did I missed it somewhere?
Thanks
The text was updated successfully, but these errors were encountered: