cancel
Showing results for 
Search instead for 
Did you mean: 

How to send data from Windows to HID keyboard?

HGaut.1
Associate II

Hello everyone! It's may be not the good place to state this problem but I am trying for days to send data from Windows to my STM32F103C8T6 CustomHID keyboard with Visual Studio in c#.

I tried many libraries and stuffs that did not work. Like this one, which was the easiest to implement: http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/ after many tries, I found it does not work for keyboard devices though.

Also tried the USBHIDDRIVER.dll that recognizes my device and send data but my HID keyboard does like it does not receive nothing.

Descriptor:

char ReportDescriptor[79] = {
    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)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x05,                    //   REPORT_COUNT (5)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x03,                    //   REPORT_SIZE (3)
    0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
    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)
    0x06, 0x00, 0xff,              // USAGE_PAGE (Vendor Defined Page 1)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0x15, 0x00,                    // LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              // LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    // REPORT_SIZE (8)
    0x95, 0x04,                    // REPORT_COUNT (4)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0xc0                           // END_COLLECTION
};

And the part of the code that handles the receiving part:

static int8_t CUSTOM_HID_OutEvent_FS(uint8_t *buffer)
{
  /* USER CODE BEGIN 6 */
	if(buffer[1] == 0x01 || buffer[1] == 1 || buffer[1] == '1' || buffer[2] == 0x01 || buffer[2] == 1 || buffer[2] == '1')
	{
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 1);
	}
 
  return (USBD_OK);
  /* USER CODE END 6 */
}

Thank's to help me, I am beginning in the 'programming game'.

2 REPLIES 2
Pavel A.
Evangelist III

Windows protects keyboards (and mice) so user applications cannot access them like other HID devices.

Keyboard LEDs can be set via the SetKeyboardState  API, but this will affect all attached keyboards.

For more info, you're welcome to Stack Overflow.

Unfortunately Microsoft just killed off most of their MSDN forums, and their new Q&A system is similar to SO but uglier - so why not to move to Stack Overflow right away.

-- pa

HGaut.1
Associate II

I uploaded the same question on Stack Overflow without any response yet.

The LEDs part are made, working 100% affecting all attached keyboards. Thank you though for helping me.