我已经知道如何做到这一点。简而言之,您必须将包含字节的“功能报告” 0x9, 0x0, 0x0, 0x0
作为根发送到适当的Hidraw设备。
您可以使用以下命令找到合适的hidraw设备:
dmesg | grep Apple | grep Keyboard | grep input0 | tail -1 | sed -e 's/.*hidraw\([[:digit:]]\+\).*/\/dev\/hidraw\1/'
发送魔术控制包的代码如下。用gcc编译,将hidraw设备作为参数。所以整个流程是:
- 将以下代码另存为
disable-capslock-delay.c
gcc -o disable-capslock-delay disable-capslock-delay.c
HIDDEVICE=$(dmesg | grep Apple | grep Keyboard | grep input0 | tail -1 | sed -e 's/.*hidraw\([[:digit:]]\+\).*/\/dev\/hidraw\1/')
sudo ./disable-capslock-delay $HIDDEVICE
每次重新启动(或拔下并重新插入键盘)时,都必须执行步骤3和4。您可以将它们放入/etc/rc.local
(或与发行版等效的文件中)以在启动时执行它们(sudo
在这种情况下不需要;您可能希望将已编译的二进制文件移入/usr/local/sbin/
或移入某物)。
我已经对供应商ID,设备ID和报告描述符长度进行了一些安全检查。如果您的模型与我的模型不同,则可能必须更改后两者。
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
if (argc != 2 || strcmp(argv[1], "-h") == 0) {
printf("Pass a hidraw device as the first and only parameter!\n");
printf("You may find the right device with:\n");
printf(" dmesg | grep Apple | grep Keyboard | grep input0 | tail -1 | "
"sed -e 's/.hidraw\([[:digit:]]\+\)./\/dev\/hidraw\1/'\n");
return 1;
}
int fd, i, res, desc_size = 0;
char buf[256];
struct hidraw_devinfo info;
char *device = argv[1];
fd = open(device, O_RDWR | O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
return 1;
}
memset(&info, 0, sizeof(info));
memset(buf, 0, sizeof(buf));
// Get Report Descriptor Size
res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);
if (res < 0) {
perror("HIDIOCGRDESCSIZE");
}
if (desc_size != 75) {
printf("Error: unexpected descriptor size %d; you've probably got "
"the wrong hidraw device!\n", desc_size);
return 1;
}
// Get Raw Info
res = ioctl(fd, HIDIOCGRAWINFO, &info);
if (res < 0) {
perror("HIDIOCGRAWINFO");
} else {
if (info.vendor != 0x05ac) {
printf("Error: Wrong vendor ID, make sure you got the right "
"hidraw device!\n");
return 1;
}
if (info.product != 0x0250) {
printf("Warning: Unknown product ID 0x%x!\n", info.product);
}
}
// Get Feature
buf[0] = 0x09; // Report Number
res = ioctl(fd, HIDIOCGFEATURE(256), buf);
if (res < 0) {
perror("HIDIOCGFEATURE");
} else {
printf("HID Feature Report (before change):\n\t");
for (i = 0; i < res; i++) printf("%hhx ", buf[i]);
puts("\n");
}
// Set Feature
buf[0] = 0x09; // Report Number
buf[1] = 0x00; // Report data
buf[2] = 0x00; // padding
buf[3] = 0x00; // padding
res = ioctl(fd, HIDIOCSFEATURE(4), buf);
if (res < 0) {
perror("HIDIOCSFEATURE");
} else {
printf("Caps lock delay disabled.\n");
}
// Get Feature
buf[0] = 0x09; // Report Number
res = ioctl(fd, HIDIOCGFEATURE(256), buf);
if (res < 0) {
perror("HIDIOCGFEATURE");
} else {
printf("HID Feature Report (after change):\n\t");
for (i = 0; i < res; i++) printf("%hhx ", buf[i]);
puts("\n");
}
close(fd);
return 0;
}