linux – USB键盘和setxkbmap

在我的〜/ .xinitrc中,我通过启动setxkbmap命令重置键映射:

setxkbmap -option ctrl:nocaps,terminate:ctrl_alt_bksp

但是如果我在X11启动后插入我的USB键盘,我的USB键盘上的CapsLock键不会映射到“CTRL”功能,但如果我重新运行上面的命令,它就可以工作.

问题是,我怎样才能自动完成这项工作?如果我尝试解析/ var / log / messages中的内核消息,它根本就不酷.

感谢你的任何答案;-P

解决方法:

观看hal / dbus / udev或等效内容,并在添加设备时触发脚本.看看https://askubuntu.com/questions/27948/usb-device-changes-using-udev-and-d-bushttp://packages.python.org/pyudev/api/index.html.

使用pyudev的示例应用程序

$python watch_the_mouse.py  
remove "Logitech USB Optical Mouse"
remove "Logitech USB Optical Mouse"
remove Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/0003:046D:C05A.002F/hidraw/hidraw0')
remove Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/input/input53')
remove Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/0003:046D:C05A.002F')
remove Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0')
remove Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1')
add Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1')
add Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0')
add Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/input/input54')
add Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/0003:046D:C05A.0030')
add Device(u'/sys/devices/pci0000:00/0000:00:06.1/usb2/2-2/2-2.1/2-2.1:1.0/0003:046D:C05A.0030/hidraw/hidraw0')
add "Logitech USB Optical Mouse"
add "Logitech USB Optical Mouse"
上一篇:c-X11 / Xlib.h中缺少XGetPixel()吗?


下一篇:c – 如何从用户代码移动鼠标光标?