4

I often connect a USB keyboard to my laptop, and when I plug it in, the default repeat rate is not what I want. I tried changing it using a udev script by adding a rule

`ACTION=="add", ATTRS{name}=="Dell Dell Multimedia Pro Keyboard", RUN+="set-keyboard.sh"`

with the set-keyboard.sh script calling

xset -display :0 r rate 500 50; xset -display :0 b off

The problem is that this sets the repeat rate and beep of the laptop built-in keyboard, not the USB keyboard. (That is, if I type xset q on the built-in keyboard, it shows the right settings, but if I type xset q on the USB keyboard, it's still set to the wrong rate.)

Is there a way to let xset know which keyboard to set, or some other way to go about this?

1
  • 1
    Have you tried being more selective in your udev rule? Like using the vendor and product id in the selection part of the rule?
    – lgeorget
    Commented Aug 4, 2013 at 21:09

4 Answers 4

2

After some poking around, I found from https://bugzilla.redhat.com/show_bug.cgi?id=601853 that the issue may be that xorg resets the keyboard rate after udev has run, so even though my udev script was definitely being executed, its actions were promptly undone by xorg.

However, that page also has the fix: if I run startx with the options startx -- -ardelay 500 -arinterval 20, then my settings are preserved even when a new keyboard is plugged in.

1
  • Having the same issue. Any way to integrate your fix into xorg.conf? Commented Feb 4, 2015 at 15:22
1

You can try this command to determine what the udev ID would be for your USB keyboard. Run this and then plug your keyboard in:

$ udevadm monitor --udev --subsystem-match=usb

Example - monitor

I have an old Sun Microsystems USB keyboard. When I unplug it and plug it back in I get the following udev messages:

$ udevadm monitor --udev --subsystem-match=usb
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

UDEV  [1375655040.466080] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV  [1375655040.557791] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 (usb)
UDEV  [1375655044.586242] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 (usb)
UDEV  [1375655044.589087] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV  [1375655049.880514] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV  [1375655049.905175] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 (usb)

So the udev ID you could put into your rule would make use of this piece of the above output, /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2.

Example - export

You can also just export the entire udev DB and manually scan through it:

$ udevadm info --export-db
...
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2
N: bus/usb/002/009
S: char/189:136
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2
E: SUBSYSTEM=usb
E: DEVNAME=bus/usb/002/009
E: ID_VENDOR=0430
E: ID_VENDOR_ENC=0430
E: ID_VENDOR_ID=0430
E: ID_MODEL=0005
E: ID_MODEL_ENC=0005
E: ID_MODEL_ID=0005
E: ID_REVISION=0102
E: ID_SERIAL=0430_0005
E: ID_BUS=usb
E: ID_USB_INTERFACES=:030101:
E: MAJOR=189
E: MINOR=136
E: DEVTYPE=usb_device
E: DRIVER=usb
E: DEVICE=/proc/bus/usb/002/009
E: PRODUCT=430/5/102
E: TYPE=0/0/0
E: BUSNUM=002
E: DEVNUM=009
E: DEVLINKS=/dev/char/189:136
...

And make use of some other unique characteristic from the above output in your udev rule too.

References

0

To solve this, I've created https://github.com/SFTtech/xautocfg.

It gets an event from the X server when new keyboards are attached to it - then it can apply configuration to the keyboard like setting the key repeat rate and delay.

You don't need root privileges, edit the launch options to -ardelay 200 -arinterval 20 or use hacky udev rules. xautocfg just runs as your user (preferrably as systemd user service) and updates the device config.

-1

So finally after digging around the net for one year I got it working today.

Source: https://newbedev.com/udev-rule-to-auto-load-keyboard-layout-when-usb-keyboard-plugged-in

As @TomYan already mentioned xset is an X11 program. So you'll have to hardcode the DISPLAY and XAUTHORITY env variables.

Basically the workaround is to run the script in background with a short delay. So udev can activate the keyboard before you xset the keyboard. In the solution mentioned above the udev calls a script which in turn calls a second script in the background which then calls xset. In fact this can be shortened to one script.

set-keyboard.sh

#!/usr/bin/env bash

(
    sleep 1

    DISPLAY=":0.0"
    XAUTHORITY="/home/your-profile/.Xauthority"
    export DISPLAY XAUTHORITY

    xset r rate 250 50
) &
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .