如何获得适用于热插拔 USB 键盘的键盘重复率?
我做了一个udev规则来设置键盘重复延迟和速率,/etc/udev/rules.d/99-usb-keyboard.rules
内容如下:
ACTION=="add", SUBSYSTEM=="usb", RUN+="/home/michael/bin/keyboard_settings.sh"
键盘设置.sh:
#!/bin/bash
# Set keyboard repeat delay and rate
xset -display :0.0 r rate 250 40
udev 似乎看到了这一点,使用命令udevadm test /sys/bus/usb/devices/3-2\:1.0/
read rules file: /etc/udev/rules.d/99-usb-keyboard.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 37438 bytes strings
31709 strings (264322 bytes), 28154 de-duplicated (230440 bytes), 3556 trie nodes used
IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:11
RUN '/home/myuser/bin/keyboard_settings.sh' /etc/udev/rules.d/99-usb-keyboard.rules:1
unable to create temporary db file '/run/udev/data/+usb:3-2:1.0.tmp': Permission denied
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0
DEVTYPE=usb_interface
DRIVER=usbhid
ID_VENDOR_FROM_DATABASE=Hewlett-Packard
INTERFACE=3/1/1
MODALIAS=usb:v03F0p0325d0102dc00dsc00dp00ic03isc01ip01in00
PRODUCT=3f0/325/102
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=4145997461
run: '/home/myuser/bin/keyboard_settings.sh'
然而,这实际上并没有改变重复率。笔记本电脑键盘的设置正确,但外接 USB 键盘的设置不正确。应用 udev 规则后,Xorg 是否会覆盖设置?我怎样才能找到答案?
我在 Xorg.0.log 中看到这一点,表明 X11 正在处理一些事情,但没有任何规则/usr/share/X11/xorg.conf.d/
对键盘做任何事情。
[164570.705] (II) config/udev: Adding input device Lite-On Technology Corp. HP Basic USB Keyboard (/dev/input/event6)
[164570.705] (**) Lite-On Technology Corp. HP Basic USB Keyboard: Applying InputClass "evdev keyboard catchall"
[164570.705] (**) Lite-On Technology Corp. HP Basic USB Keyboard: Applying InputClass "Keyboard Defaults"
[164570.705] (II) Using input driver 'evdev' for 'Lite-On Technology Corp. HP Basic USB Keyboard'
[164570.705] (**) Lite-On Technology Corp. HP Basic USB Keyboard: always reports core events
[164570.705] (**) evdev: Lite-On Technology Corp. HP Basic USB Keyboard: Device: "/dev/input/event6"
[164570.705] (--) evdev: Lite-On Technology Corp. HP Basic USB Keyboard: Vendor 0x3f0 Product 0x325
[164570.705] (--) evdev: Lite-On Technology Corp. HP Basic USB Keyboard: Found keys
[164570.705] (II) evdev: Lite-On Technology Corp. HP Basic USB Keyboard: Configuring as keyboard
[164570.705] (**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/input/input34/event6"
[164570.705] (II) XINPUT: Adding extended input device "Lite-On Technology Corp. HP Basic USB Keyboard" (type: KEYBOARD, id 11)
[164570.705] (**) Option "xkb_rules" "evdev"
[164570.705] (**) Option "xkb_model" "pc105"
[164570.705] (**) Option "xkb_layout" "us"
答案1
不要为此使用 udev。
注意:以下仅适用于最新版本的 Xorg,请参阅这个变化从2020年开始。
对于较旧的 Xorg,您可以使用-ardelay
和-arinterval
命令行选项;如果您正在使用xdm
,则可以将这些选项添加到/etc/X11/xdm/Xservers
.
如果您正在使用gdm3
(正在使用硬连线的 Xorg 命令行),我只能为您感到难过。
只需使用一个xorg.conf
片段并在那里设置重复率即可。
% cat /etc/X11/xorg.conf.d/99-keyboard.conf
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
# Option "XkbLayout" set in /etc/default/keyboard
# Option "XkbOptions" ditto
Option "AutoRepeat" "250 50"
EndSection
答案2
因此,在网上挖掘了一年之后,我今天终于让它工作了。
来源:https://newbedev.com/udev-rule-to-auto-load-keyboard-layout-when-usb-keyboard-plugged-in
xset
是一个X11程序。因此,您必须对DISPLAY
和XAUTHORITY
env 变量进行硬编码。
基本上,解决方法是在后台短暂延迟运行脚本。因此 udev 可以在 xset 键盘之前激活键盘。在上面提到的解决方案中,udev 调用一个脚本,该脚本又在后台调用第二个脚本,然后该脚本调用xset
.事实上,这可以缩短为一个脚本。
/home/michael/bin/keyboard_settings.sh
#!/usr/bin/env bash
(
sleep 1
DISPLAY=":0.0"
XAUTHORITY="/home/your-profile/.Xauthority"
export DISPLAY XAUTHORITY
xset r rate 250 50
) &