title: How to set LEDs of a USB keyboard under Windows
body: <p>I'm trying to set the keyboard LEDs of a USB keyboard. I already tried / know the following:</p>
  <ol>
  <li><p>To set <a href="https://en.wikipedia.org/wiki/PS/2_port" rel="nofollow noreferrer">PS/2</a> keyboard LEDs you can use the
  CreateFile(&quot;\\.\Keybd&quot;, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
  DeviceIoControl(hKeybd, IOCTL_KEYBOARD_SET_INDICATORS...</p>
  </li>
  <li><p>To set the LEDs of a truly <a href="https://en.wikipedia.org/wiki/Human_interface_device" rel="nofollow noreferrer">HID</a> compliant keyboard you can use DirectInput, SendDeviceData with the usage page 8.</p>
  </li>
  <li><p>You can use SendInput / keybd_event. But this will also changes the state. So when you change CAPS LOCK with this method while the user is typing, he/she will get upper and lower case letters :-)</p>
  </li>
  </ol>
  <p>When I investigated method 2 with two keyboards, the SendDeviceData function always returns E_NOTIMPL. It seems a lot of USB keyboard manufacturers rely on the build-in HID driver. In this case the HID driver reports that keyboard as a PC enhanced keyboard ans says it's an &quot;emulation&quot;. But the Windows HID emulation doesn't support SendDeviceData.</p>
  <p>So I suspect there must be another way to set the keyboards LEDs. Windows must be talking to the USB keyboard to set the LEDs :-)</p>
  <p>How can I change the keyboard LEDs without changing the keyboard state?</p>