title: How to send data from Windows to HID keyboard?
body: <p>I am trying for days to send data from Windows to my STM32F103C8T6 CustomHID keyboard with Visual Studio in c#.</p>
  <p>I tried many libraries and stuffs that did not work. Like this one, which was the easiest to implement: <a href="http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/" rel="nofollow noreferrer">http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/</a> after many tries, I found sending datas does not work for keyboard devices with this library.
  At this state, the application is only capable to detect if the device is connected or not, sending data does not work.</p>
  <p>Descriptor (79):</p>
  <pre><code>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
  </code></pre>
  <p>Part of the code that handles the receiving part:</p>
  <pre><code>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 */
  } 
  </code></pre>
  <p>Visual Studio part with USBHIDDRIVER.dll (Florian's library):</p>
  <pre><code>USBHIDDRIVER.USBInterface usb = new USBInterface(&quot;vid_0483&quot;, &quot;pid_5750&quot;);
          public Form1()
          {
              InitializeComponent();
              if (usb.Connect())
                  MessageBox.Show(&quot;Connecté!&quot;);
              else
                  MessageBox.Show(&quot;Deconnecté&quot;);
          }
   private void button1_Click(object sender, EventArgs e)
          {
            
              byte[] Buffer = new byte[64];
              for(int i = 0; i&gt;=64; i++)
              {
                  Buffer[i] = 1;
              }
  
              usb.write(Buffer);
          }
  </code></pre>
  <p>Thank's for you help considering I am a beginner!</p>