如何在Windows下设置USB键盘的LED
我正在尝试设置 USB 键盘的键盘 LED。我已经尝试/了解以下内容:
设置PS/2键盘LED你可以使用 CreateFile("\\.\Keybd", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); DeviceIoControl(hKeybd, IOCTL_KEYBOARD_SET_INDICATORS...
设置真正符合 HID 标准的 LED键盘您可以使用 DirectInput、SendDeviceData 配合使用页面 8。
您可以使用SendInput / keybd_event。但这也会改变状态。因此,当用户在输入时使用此方法更改 CAPS LOCK 时,他/她将获得大写和小写字母:-)
当我使用两个键盘研究方法 2 时,SendDeviceData 函数始终返回 E_NOTIMPL。看来很多 USB 键盘制造商都依赖内置的 HID 驱动程序。在这种情况下,HID 驱动程序将键盘报告为 PC 增强型键盘,并表示它是“仿真”。但Windows HID仿真不支持SendDeviceData。
所以我怀疑一定有另一种方法来设置键盘 LED。 Windows 必须与 USB 键盘通信才能设置 LED :-)
如何在不更改键盘状态的情况下更改键盘 LED?
I'm trying to set the keyboard LEDs of a USB keyboard. I already tried / know the following:
To set PS/2 keyboard LEDs you can use the
CreateFile("\\.\Keybd", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
DeviceIoControl(hKeybd, IOCTL_KEYBOARD_SET_INDICATORS...To set the LEDs of a truly HID compliant keyboard you can use DirectInput, SendDeviceData with the usage page 8.
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 :-)
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 "emulation". But the Windows HID emulation doesn't support SendDeviceData.
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 :-)
How can I change the keyboard LEDs without changing the keyboard state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 HID 描述符工具查看 每个键盘的 HID 报告描述符。键盘需要实现使用第 8 页(“LED”)。否则,可能无法通过 USB 接口控制这些指示器,或者可能以非标准方式完成。
或者,您可以尝试使用 设置特殊按键状态keybd_event 也许 Windows 会自动为您切换 LED。
Use the HID Descriptor Tool to view the HID Report Descriptors for each keyboard. The keyboard needs to implement usage page 8 ("LEDs"). Otherwise, control of those indicators may not be available through the USB interface or it may be done in a non-standard way.
Alternatively, you could try setting the special key states with keybd_event and maybe Windows will automagically toggle the LED for you.