USB键盘和setxkbmap

时间:2011-03-24 01:30:30

标签: linux keyboard usb xorg

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

  

setxkbmap -option ctrl:nocaps,terminate:ctrl_alt_bksp

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

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

感谢您的任何答案;-P

2 个答案:

答案 0 :(得分:5)

如果您具有root访问权限,则可以在包含

/etc/X11/xorg.conf.d/中放置xorg配置文件(例如,60-keyboard-override.conf)
Section "InputClass"
        Identifier "evdev keyboard catchall"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option  "XkbOptions"  "ctrl:nocaps,terminate:ctrl_alt_bksp"
EndSection

要测试它,请运行setxkbmap -query以查看是否正在设置选项:

rules:      evdev
model:      pc104
layout:     us
options:    ctrl:nocaps,terminate:ctrl_alt_bksp

答案 1 :(得分:1)

观看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"
相关问题