Sto eseguendo Ubuntu 9.10 (Karmic Koala) su un laptop e vorrei che NumLock si attivasse automaticamente a seconda che la mia tastiera USB sia collegata (blocco numerico attivo) o scollegata (blocco numerico spento).
Per fare ciò, ho prima installato il pacchetto "numlockx". numlockx on
e numlockx off
funziona benissimo.
Per collegarmi al sistema del dispositivo, ho pensato di usare udev. Ho letto "Scrivere regole udev" , ma ho problemi a far funzionare la regola udev.
Innanzitutto, ecco un esempio dmesg
dell'output:
[20906.985102] usb 3-2: nuovo dispositivo USB a bassa velocità con uhci_hcd e indirizzo 6 [20907.166403] usb 3-2: configurazione n. 1 scelta da 1 scelta [20907.192904] input: Microsoft Natural® Ergonomic Keyboard 4000 as /devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.0/input/input20 [20907.193100] microsoft 0003: 045E: 00DB.000B: input, hidraw1: tastiera USB HID v1.11 [Microsoft Natural® Ergonomic Keyboard 4000] su usb-0000: 00: 1a.0-2 / input0 [20907.217810] input: Microsoft Natural® Ergonomic Keyboard 4000 as /devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21 [20907.217979] microsoft 0003: 045E: 00DB.000C: input, hidraw2: dispositivo USB HID v1.11 [Microsoft Natural® Ergonomic Keyboard 4000] su usb-0000: 00: 1a.0-2 / input1
Ho usato udevadm info
per raccogliere le informazioni sul dispositivo:
> udevadm info -a -p /devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21 guardando il dispositivo '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21': KERNEL == "input21" SUBSYSTEM == "input" DRIVER == "" ATTR {Phys} == "USB-0000: 00: 1a.0-2 / input1" ATTR {} uniq == "" ATTR {modalias} == "input: b0003v045Ep00DBe0111-e0,1,2,3,4,14, k71,72,73,74,75,77,79,7A, 7B, 7C, 7D, 7E, 7F, 80 , 81,82,83,84,85,86,87,88,89,8A, 8B, 8C, 8E, 90,96,98,9B, 9C, 9E, 9F, A1, A3, A4, A5, A6 , A7, A8, A9, AB, AC, AD, AE, B0, B1, B2, B3, B4, B5, B6, B8, B9, BA, BB, BC, BD, BE, BF, C0, C1, C2 , CE, CF, D0, D1, D2, D5, D9, DB, DF, E2, E7, E8, E9, EA, EB, F0,100,162,166,16A, 16E, 178,179,17A, 17B, 17C, 17D, 17F , 180,181,182,185,18C, 18D, 192,193,195,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA, 1AB, 1AC, 1AD, 1AE, 1B0,1B1,1B7, r6, a20, m4 , lsfw" guardando il dispositivo genitore '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1': NOCCIOLI == "3-2: 1.1" SOTTOSISTEMI == "usb" DRIVER == "USBHID" ATTR {} bInterfaceNumber == "01" ATTRS {bAlternateSetting} == "0" ATTR {bNumEndpoints} == "01" ATTR {} bInterfaceClass == "03" ATTR {} bInterfaceSubClass == "00" ATTR {} bInterfaceProtocol == "00" ATTR {modalias} == "usb: v045Ep00DBd0173dc00dsc00dp00ic03isc00ip00" ATTR {} supports_autosuspend == "1" guardando il dispositivo genitore '/devices/pci0000:00/0000:00:1a.0/usb3/3-2': NOCCIOLI == "3-2" SOTTOSISTEMI == "usb" DRIVER == "usb" ATTR {configurazione} == "" ATTRS {bNumInterfaces} == "2" ATTR {} bConfigurationValue == "1" Attrs {bmAttributes} == "a0" ATTR {} bMaxPower == "100mA" ATTR {} urbnum == "532" ATTR {} idVendor == "045e" ATTR {} idProduct == "00db" ATTR {} bcdDevice == "0173" ATTR {} bDeviceClass == "00" ATTR {} bDeviceSubClass == "00" ATTR {} bDeviceProtocol == "00" ATTR {bNumConfigurations} == "1" ATTR {} bMaxPacketSize0 == "8" ATTR {Velocità} == "1.5" ATTR {} BusNum == "3" ATTR {} devnum == "6" ATTRS {versione} == "2.00" ATTR {} maxchild == "0" Attrs {} == stranezze "0x0" ATTR {autorizzato} == "1" ATTR {produttore} == "Microsoft" guardando il dispositivo genitore '/devices/pci0000:00/0000:00:1a.0/usb3': NOCCIOLI == "USB3" SOTTOSISTEMI == "usb" DRIVER == "usb" ATTR {configurazione} == "" ATTRS {bNumInterfaces} == "1" ATTR {} bConfigurationValue == "1" Attrs {bmAttributes} == "E0" ATTRS {bMaxPower} == "0mA" ATTR {} urbnum == "127" ATTR {} idVendor == "1d6b" ATTR {} idProduct == "0001" ATTR {} bcdDevice == "0206" ATTR {} bDeviceClass == "09" ATTR {} bDeviceSubClass == "00" ATTR {} bDeviceProtocol == "00" ATTR {bNumConfigurations} == "1" ATTR {} bMaxPacketSize0 == "64" ATTR {Velocità} == "12" ATTR {} BusNum == "3" ATTR {} devnum == "1" ATTRS {versione} == "1.10" ATTR {} maxchild == "2" Attrs {} == stranezze "0x0" ATTR {autorizzato} == "1" ATTRS {producer} == "Linux 2.6.31-16-generic uhci_hcd" ATTRS {product} == "Controller host UHCI" ATTR {serial} == "0000: 00: 1a.0" ATTR {} authorized_default == "1" guardando il dispositivo genitore '/devices/pci0000:00/0000:00:1a.0': NOCCIOLI == "0000: 00: 1a.0" SOTTOSISTEMI == "pci" DRIVER == "uhci_hcd" ATTR {vendor} == "0x8086" ATTR {dispositivo} == "0x2937" ATTR {} subsystem_vendor == "0x1558" ATTR {} subsystem_device == "0x0860" ATTR {class} == "0x0c0300" ATTR {} IRQ == "16" Attrs {local_cpus} == "FF" ATTR {} local_cpulist == "0-7" ATTR {modalias} == "PCI: v00008086d00002937sv00001558sd00000860bc0Csc03i00" ATTR {} broken_parity_status == "0" ATTR {} msi_bus == "" guardando il dispositivo genitore '/ devices / pci0000: 00': NOCCIOLI == "pci0000: 00" SOTTOSISTEMI == "" DRIVERS == ""
Quindi ho creato un file chiamato /etc/udev/rules.d/usb-keyboard.rules
:
# Attiva NumLock quando la tastiera è collegata. AZIONE == "aggiungi", ATTRS {produttore} == "Microsoft", SOTTOSISTEMA == "input", RUN + = "/ usr / bin / numlockx on" # Disattiva NumLock quando la tastiera è scollegata. AZIONE == "rimuovi", ATTRS {produttore} == "Microsoft", SUBSYSTEM == "input", RUN + = "/ usr / bin / numlockx off"
Ho usato udevadm test
per verificare che le regole siano corrette:
> udevadm test --action = aggiungi /devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21 run_command: calling: test udevadm_test: versione 147 [...] parse_file: lettura '/etc/udev/rules.d/usb-keyboard.rules' come file delle regole udev_rules_new: le regole utilizzano token token 180864 (15072 * 12 byte), buffer 31614 byte udev_rules_new: indice temporaneo utilizzato 49760 byte (2488 * 20 byte) udev_device_new_from_syspath: il dispositivo 0x28d7d80 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21' udev_rules_apply_to_event: RUN '/ sbin / modprobe -b $ env {MODALIAS}' /lib/udev/rules.d/80-drivers.rules:5 udev_rules_apply_to_event: RUN 'socket: @ / org / freedesktop / hal / udev_event' /lib/udev/rules.d/90-hal.rules:2 udev_device_new_from_syspath: il dispositivo 0x28d8560 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1' udev_device_new_from_syspath: il dispositivo 0x28d8708 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2' udev_rules_apply_to_event: RUN '/ usr / bin / numlockx su' /etc/udev/rules.d/usb-keyboard.rules:7 udevadm_test: UDEV_LOG = 6 udevadm_test: DEVPATH = / devices / pci0000: 00/0000: 00: 1a.0 / usb3 / 3-2 / 3-2: 1.1 / input / input21 udevadm_test: PRODUCT = 3 / 45e / db / 111 udevadm_test: NAME = "Microsoft Natural® Ergonomic Keyboard 4000" udevadm_test: PHYS = "usb-0000: 00: 1a.0-2 / input1" udevadm_test: UNIQ = "" udevadm_test: EV == 10001f udevadm_test: KEY == 837fff 2c3027 bf004444 0 0 1 10f84 8a27c007 ff7f7bfa d9415fff febeffdf ffefffff ffffffff fffffffe udevadm_test: REL == 40 udevadm_test: ABS == 1 0 udevadm_test: MSC == 10 udevadm_test: MODALIAS = input: b0003v045Ep00DBe0111-e0,1,2,3,4,14, k71,72,73,74,75,77,79,7A, 7B, 7C, 7D, 7E, 7F, 80,81, 82,83,84,85,86,87,88,89,8A, 8B, 8C, 8E, 90,96,98,9B, 9C, 9E, 9F, A1, A3, A4, A5, A6, A7, A8, A9, AB, AC, AD, AE, B0, B1, B2, B3, B4, B5, B6, B8, B9, BA, BB, BC, BD, BE, BF, C0, C1, C2, CE, CF, D0, D1, D2, D5, D9, DB, DF, E2, E7, E8, E9, EA, EB, F0,100,162,166,16A, 16E, 178,179,17A, 17B, 17C, 17D, 17F, 180.181.182.185, 18C, 18D, 192,193,195,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA, 1AB, 1AC, 1AD, 1AE, 1B0,1B1,1B7, r6, A20, m4, lsfw udevadm_test: ACTION = add udevadm_test: SUBSYSTEM = input udevadm_test: run: '/ sbin / modprobe -b input: b0003v045Ep00DBe0111-e0,1,2,3,4,14, k71,72,73,74,75,77,79,7A, 7B, 7C, 7D, 7E , 7F, 80,81,82,83,84,85,86,87,88,89,8A, 8B, 8C, 8E, 90,96,98,9B, 9C, 9E, 9F, A1, A3, A4 , A5, A6, A7, A8, A9, AB, AC, AD, AE, B0, B1, B2, B3, B4, B5, B6, B8, B9, BA, BB, BC, BD, BE, BF, C0 , C1, C2, CE, CF, D0, D1, D2, D5, D9, DB, DF, E2, E7, E8, E9, EA, EB, F0,100,162,166,16A, 16E, 178,179,17A, 17B, 17C , 17D, 17F, 180,181,182,185,18C, 18D, 192,193,195,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA, 1AB, 1AC, 1AD, 1AE, 1B0,1B1,1B7, r6 , a20, m4, lsfw' udevadm_test: run: 'socket: @ / org / freedesktop / hal / udev_event' udevadm_test: run: '/ usr / bin / numlockx on'
Ed ecco il test "rimuovi":
> udevadm test --action = remove /devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21 run_command: calling: test udevadm_test: versione 147 [...] parse_file: lettura '/etc/udev/rules.d/usb-keyboard.rules' come file delle regole udev_rules_new: le regole utilizzano token token 180864 (15072 * 12 byte), buffer 31614 byte udev_rules_new: indice temporaneo utilizzato 49760 byte (2488 * 20 byte) udev_device_new_from_syspath: il dispositivo 0xd2fd80 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1/input/input21' udev_rules_apply_to_event: RUN 'socket: @ / org / freedesktop / hal / udev_event' /lib/udev/rules.d/90-hal.rules:2 udev_device_new_from_syspath: il dispositivo 0xd2fff8 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2/3-2:1.1' udev_device_new_from_syspath: il dispositivo 0xd30690 ha devpath '/devices/pci0000:00/0000:00:1a.0/usb3/3-2' udev_rules_apply_to_event: RUN '/ usr / bin / numlockx off' /etc/udev/rules.d/usb-keyboard.rules:10 udevadm_test: UDEV_LOG = 6 udevadm_test: DEVPATH = / devices / pci0000: 00/0000: 00: 1a.0 / usb3 / 3-2 / 3-2: 1.1 / input / input21 udevadm_test: PRODUCT = 3 / 45e / db / 111 udevadm_test: NAME = "Microsoft Natural® Ergonomic Keyboard 4000" udevadm_test: PHYS = "usb-0000: 00: 1a.0-2 / input1" udevadm_test: UNIQ = "" udevadm_test: EV == 10001f udevadm_test: KEY == 837fff 2c3027 bf004444 0 0 1 10f84 8a27c007 ff7f7bfa d9415fff febeffdf ffefffff ffffffff fffffffe udevadm_test: REL == 40 udevadm_test: ABS == 1 0 udevadm_test: MSC == 10 udevadm_test: MODALIAS = input: b0003v045Ep00DBe0111-e0,1,2,3,4,14, k71,72,73,74,75,77,79,7A, 7B, 7C, 7D, 7E, 7F, 80,81, 82,83,84,85,86,87,88,89,8A, 8B, 8C, 8E, 90,96,98,9B, 9C, 9E, 9F, A1, A3, A4, A5, A6, A7, A8, A9, AB, AC, AD, AE, B0, B1, B2, B3, B4, B5, B6, B8, B9, BA, BB, BC, BD, BE, BF, C0, C1, C2, CE, CF, D0, D1, D2, D5, D9, DB, DF, E2, E7, E8, E9, EA, EB, F0,100,162,166,16A, 16E, 178,179,17A, 17B, 17C, 17D, 17F, 180.181.182.185, 18C, 18D, 192,193,195,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA, 1AB, 1AC, 1AD, 1AE, 1B0,1B1,1B7, r6, A20, m4, lsfw udevadm_test: ACTION = rimuovi udevadm_test: SUBSYSTEM = input udevadm_test: run: 'socket: @ / org / freedesktop / hal / udev_event' udevadm_test: run: '/ usr / bin / numlockx off'
Il problema è che quando la tastiera è collegata o scollegata, lo stato di NumLock non cambia. Ho provato a riavviare il servizio udev, senza fortuna. Le mie regole udev sono sbagliate? Sto andando in questo modo nel modo sbagliato?