USB键盘和setxkbmap [关闭]
收藏

在My~/.NeRITC中,我通过启动SETXKBMAP命令重置键映射:
setxkbmap-选项ctrl:nocaps,终止: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"

    公众号
    关注公众号订阅更多技术干货!