我一直在尝试使用 hidapi 控制鼠标上的 LED,但每当我运行 hid_write() 时,它都会返回 -1。我发现调用 WriteFile() 时在函数内部引发了错误,并且错误是“访问被拒绝”。有一个软件 (iCue) 可以控制 LED 并使用 wireshark 我想我已经知道要发送给鼠标的内容了:
我的代码:
int main() {
CorsairHIDDevices corsair_devs; //Initialize vector of HID devices
int num = detectCorsairMouseHIDDevice(corsair_devs); //Enumerates HID devices and adds the mouse devices to corsair_devs. Returns number of devices added.
hid_device* handle;
handle = hid_open(corsair_devs[0].vendor_id, corsair_devs[0].product_id, nullptr);
//Creates message to send to mouse based on info from wireshark
int logoLed = 1;
int sideLed = 1;
int scrollLed = 1;
int ledCode = logoLed + 2 * sideLed + 4 * scrollLed;
int red = 255;
int green = 0;
int blue = 0;
uint8_t buf[64] = { 0 };
buf[0] = 0x07; buf[1] = 0xaa;
buf[4] = ledCode;
buf[5] = 0x07; buf[8] = 0x64;
buf[9] = red; buf[12] = red;
buf[10] = green; buf[13] = green;
buf[11] = blue; buf[14] = blue;
buf[15] = 0x05;
hid_write(handle, buf, 64); //Sends message to mouse. Returns -1 (error).
}
枚举时,有 5 个设备对应于鼠标,我不确定这意味着什么或如何确定要使用哪个设备,但我尝试了所有设备,但都没有工作。我没有很多使用 hidapi 的经验;大部分代码都是从这里重新使用的。任何帮助将不胜感激。谢谢。