![如何使用xinput通过脚本配置多个设备?](https://linux22.com/image/58261/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8xinput%E9%80%9A%E8%BF%87%E8%84%9A%E6%9C%AC%E9%85%8D%E7%BD%AE%E5%A4%9A%E4%B8%AA%E8%AE%BE%E5%A4%87%EF%BC%9F.png)
如何配置 xinput 以使用脚本自动设置多个设备?
$ xinput --list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=12 [slave pointer (2)]
⎜ ↳ ALPS PS/2 Device id=13 [slave pointer (2)]
⎜ ↳ Corsair Corsair M65 Gaming Mouse id=15 [slave pointer (2)]
⎜ ↳ Corsair Corsair M65 Gaming Mouse id=17 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ Sleep Button id=9 [slave keyboard (3)]
↳ Laptop_Integrated_Webcam_HD id=10 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=11 [slave keyboard (3)]
↳ Dell WMI hotkeys id=14 [slave keyboard (3)]
↳ Corsair Corsair M65 Gaming Mouse id=16 [slave keyboard (3)]
问题是这两个“海盗船游戏鼠标”每次都有不同的 ID。我不知道为什么有两只鼠标......但这就是我生活的世界。如何编写脚本来设置它们的属性?我用了这个,但是下次启动时它不起作用(ID改变了):
#!/bin/sh
xinput --set-pr
op 10 "Device Accel Profile" 6
xinput --set-prop 10 "Device Accel Velocity Scaling" 5
xinput --set-prop 10 "Device Accel Constant Deceleration" 3
#xinput --set-prop 10 "Device Accel Velocity Tracker Count" 2
我曾尝试使用该名称,但它抱怨有多个匹配的设备。
任何帮助表示赞赏。
答案1
如果您需要对两者进行更改,可以使用循环
#!/bin/sh
for id in $(xinput --list | \
sed -n '/Corsair Corsair M65 Gaming Mouse.*pointer/s/.*=\([0-9]\+\).*/\1/p')
do
xinput --set-prop $id "Device Accel Profile" 6
...
whatever you want to do
...
done
答案2
您可以在名称前面添加“指针:”或“键盘:”。例如
xinput list-props 'pointer:Logitech M585/M590'
xinput list-props 'keyboard:Logitech M585/M590'