I have a STM32 demo board and I trying to configure it as a USB keyboard. I am developing it for an RTOS host system.
This is the keyboard IN report format according to the standard.
unsigned char hid_report[8]; hid_report[0]=0xE1;//E1 is scan code for shift modifier key hid_report[1]=0x00;//reserved hid_report[2]=0x04;//04 is scan code for 'a'/'A' hid_report[3]=0x00; hid_report[4]=0x00; hid_report[5]=0x00; hid_report[6]=0x00; hid_report[7]=0x00;
But if I send this to RTOS host,the system gets hanged.I tried it on Windows and the SHIFT key doesn't seem to be working.
On the other hand if I send the report as
unsigned char hid_report[8]; hid_report[0]=0x00; hid_report[1]=0x00;//reserved hid_report[2]=0xE1;//E1 is scan code for shift modifier key hid_report[3]=0x04;//04 is scan code for 'a'/'A' hid_report[4]=0x00; hid_report[5]=0x00; hid_report[6]=0x00; hid_report[7]=0x00;
In RTOS it seems to be working fine(Capital 'A' is being sent).But in Windows SHIFT key still doesn't work.
Anybody knows why is it behaving differently for two different OS and Why is it not working according to the standard?
I tried one keyboard and SHIFT + 'a' was sent as: 0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00
Which can also be read out of HID specification from usb.org
It says: "Since only one array element can be reported in each array field, modifier keys should be reported as bitmap data (a group of 1-bit variable fields). For example, keys such as CTRL, SHIFT, ALT, and GUI keys make up the 8 bit modifier byte in a standard keyboard report. Although these usage codes are defined in the Usage Table as E0–E7, the usage is not sent as array data. The modifier byte is defined as follows. Bit Key 0 LEFT CTRL 1 LEFT SHIFT 2 LEFT ALT 3 LEFT GUI 4 RIGHT CTRL 5 RIGHT SHIFT 6 RIGHT ALT 7 RIGHT GUI"
Emphasis on "the usage is not sent as array data"
So captured data seems right: 0x02 = modifier byte LEFT SHIFT 0x00 0x04 = 'a' ... 0x00
Microsoft's interpretation vs yours? They tend to code quite rigidly, and then that becomes the "standard" if you want your product to "work".
thank you, that solved the problem.