Reputation: 501
I have Leonardo/Micro device that should emulate Keyboard. I would like to modify library. The reason is I would like to be able to send raw scancodes, wheras the library does some preparation. I looked in the source code, also of HID library, dbut have difficulty to understand following points:
Upvotes: 0
Views: 2147
Reputation: 356
I will try to answer your questions the best I can. Let me know if you still have questions:
- Keyboard_::begin() and Keyboard_::end() are supposed to start and stop keboard emulation, but they have empty bodies
I believe those are just placeholders in case any initialization or cleanup would need to be done. The other libraries have the same functions (e.g. the Mouse library). I suspect they are there for consistency and just in case they are needed.
- KeyReport is especially mysterious.
typedef struct
{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
} KeyReport;
KeyReport is the data structure that represents the USB message sent to the host computer.
- What exactly happens to the keyreport? I lost track in USB_Send function in HID.cpp.
It gets sent to the host computer.
- What are modifiers, what they are doing?
Some keys are “regular” keys (e.g. A, B, 1, 2, #, etc.). Other keys are modifiers (e.g. Shift, Ctrl, Alt). The modifier keys set flags in KeyReport.modifiers. For example, the Left Shift key is 0x02.
- Is number of keys sent limited to 1 or, theoretically could be arbitrary?
The number of “regular” keys that can be press simultaneously is 6, but you could also have the modifier keys pressed (Shift, Alt, Ctrl, etc.).
FYI: I have been able to add additional keys (e.g. the numeric keypad keys) by adding new key definitions to the USBAPI.h file:
#define KEY_NUMPAD_DIVIDE 0xDC
#define KEY_NUMPAD_MULTIPLY 0xDD
#define KEY_NUMPAD_MINUS 0xDE
#define KEY_NUMPAD_PLUS 0xDF
#define KEY_NUMPAD_ENTER 0xE0
#define KEY_NUMPAD_1 0xE1
#define KEY_NUMPAD_2 0xE2
#define KEY_NUMPAD_3 0xE3
#define KEY_NUMPAD_4 0xE4
#define KEY_NUMPAD_5 0xE5
#define KEY_NUMPAD_6 0xE6
#define KEY_NUMPAD_7 0xE7
#define KEY_NUMPAD_8 0xE8
#define KEY_NUMPAD_9 0xE9
#define KEY_NUMPAD_0 0xEA
#define KEY_NUMPAD_DEL 0xEB
Upvotes: 1