Linux

如何使用 xinput 通過腳本配置多個設備?

  • September 4, 2019

如何配置 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

我曾嘗試使用該名稱,但它抱怨有多個匹配的設備。

任何幫助表示讚賞。

如果您需要對兩者進行更改,您可以使用循環

#!/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

您可以在名稱前添加“指針:”或“鍵盤:”。例如

xinput list-props 'pointer:Logitech M585/M590'
xinput list-props 'keyboard:Logitech M585/M590'

引用自:https://unix.stackexchange.com/questions/164325