检测到蓝牙输入设备后运行shell命令?

当我的鼠标连接到我的电脑时,我正在尝试使用xinput命令自动减慢我的Magic Mouse灵敏度。

我设法在rules.d下创建一个调用shell脚本的文件。 问题是它适用于除xinput命令之外的所有脚本,因为规则在其他输入设备之间列出鼠标之前启动脚本,因此xinput命令无法找到它。 所以,我的问题是,如果有一种方法只有在检测到鼠标作为输入设备或者我的问题还有其他解决方案之后才能运行我需要的命令。

从终端,鼠标连接之前BT:

 $ hcitool inq Inquiring ... 00:1E:52:EE:0C:1B clock offset: 0x33fb class: 0x3a0104 84:38:35:31:CC:6B clock offset: 0x1353 class: 0x002580 $ hcitool scan Scanning ... 84:38:35:31:CC:6B Mouse of Elios 00:1E:52:EE:0C:1B Elios 

通过BT连接鼠标后,我得到:

 $ hcitool info 84:38:35:31:CC:6B Requesting information ... BD Address: 84:38:35:31:CC:6B Device Name: Mouse of Elios LMP Version: 2.0 (0x3) LMP Subversion: 0x31c Manufacturer: Apple, Inc. (76) Features: 0xbd 0x02 0x04 0x38 0x08 0x00 0x00 0x00             

这是我在/etc/udev/rules.d中放置的udev规则:

 SUBSYSTEMS=="input", ATTRS{name}=="Mouse of Elios", RUN+="/home/elios/Documents/FixMouse.sh" 

这是我的shell脚本/home/elios/Documents/FixMouse.sh (感谢Cbhihe的回答):

 #!/bin/sh while [ ! "$(/usr/bin/hcitool info 84:38:35:31:CC:6B 2>&1 > /dev/null; echo $?)" ]; do sleep 0.1 done xinput --set-prop "Mouse of Elios" "Device Accel Constant Deceleration" 2.5 

其他信息:

 $ uname -a Linux dalek 3.19.0-30-generic #34-Ubuntu SMP Fri Oct 2 22:08:41 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux $ xinput --list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Mouse of Elios id=13 [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)] ↳ Apple, Inc Apple Keyboard id=10 [slave keyboard (3)] ↳ Apple, Inc Apple Keyboard id=11 [slave keyboard (3)] ↳ FaceTime HD Camera (Built-in) id=12 [slave keyboard (3)] $ xinput --list-props "Mouse of Elios" Device 'Mouse of Elios': Device Enabled (133): 1 Coordinate Transformation Matrix (135): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000 Device Accel Profile (527): 0 Device Accel Constant Deceleration (528): 2.500000 Device Accel Adaptive Deceleration (529): 1.000000 Device Accel Velocity Scaling (530): 10.000000 Device Product ID (253): 1452, 781 Device Node (254): "/dev/input/event5" Evdev Axis Inversion (531): 0, 0 Evdev Axes Swap (533): 0 Axis Labels (534): "Rel X" (143), "Rel Y" (144), "Rel Horiz Wheel" (517), "Rel Vert Wheel" (518) Button Labels (535): "Button Left" (136), "Button Middle" (137), "Button Right" (138), "Button Wheel Up" (139), "Button Wheel Down" (140), "Button Horiz Wheel Left" (141), "Button Horiz Wheel Right" (142) Evdev Scrolling Distance (536): 1, 1, 1 Evdev Middle Button Emulation (537): 0 Evdev Middle Button Timeout (538): 50 Evdev Third Button Emulation (539): 0 Evdev Third Button Emulation Timeout (540): 1000 Evdev Third Button Emulation Button (541): 3 Evdev Third Button Emulation Threshold (542): 20 Evdev Wheel Emulation (543): 0 Evdev Wheel Emulation Axes (544): 0, 0, 4, 5 Evdev Wheel Emulation Inertia (545): 10 Evdev Wheel Emulation Timeout (546): 200 Evdev Wheel Emulation Button (547): 4 Evdev Drag Lock Buttons (548): 0 

在yr udev规则调用的脚本中, xinput参数调整之前放置while, do, done snippet。

 #!/bin/sh while [ ! "$(/usr/bin/hcitool info 84:38:35:31:CC:6B >& /dev/null; echo $?)" ]; do sleep 0.1 done xinput --set-prop "Mouse of Elios" "Device Accel Constant Deceleration" 5.0 xinput --set-prop "Mouse of Elios" "Device Accel Adaptive Deceleration" 1.0 xinput --set-prop "Mouse of Elios" "Device Accel Velocity Scaling" 3.3 

它允许你的脚本等待0.1秒的连续时间间隔,直到鼠标被蓝牙适当地束缚并且在xinput --set-prop cmds启动之前。

请注意,您有三种方法可以调整鼠标对手部动作的响应。

  • 设备加速常数减速度(528):2.500000
  • 设备加速自适应减速(529):1.000000
  • 设备加速度缩放(530):10.000000

检查这 一点 ,然后确定这些参数值的确切含义。 为了令人满意地修改“速度缩放”,您需要知道鼠标刷新率是多少(以Hz为单位)。 您应该在鼠标的技术数据表中找到该值。 Velocity Scaling值估计为1000/refresh_rate_in_Hz 。 因此3.3假设刷新率为300Hz,10刷新率为100Hz。

你的脚本似乎没有改变默认值:

  • Device Accel Constant Deceleration (528): 2.500000
  • Device Accel Adaptive Decelaration (529): 1.000000

由yr xinput --list-props cmd …尝试修改prop_id 528的2.5值,并意识到将prop_id 529设置为1(默认值)意味着“ 没有自适应加速或减速 ”。

您根据Gilles对AU / U&L的回答改编的udev规则并不严格适用于您的案例。 你需要的是一个在“添加”你的设备时启动的规则,即一旦它的存在首先触发内核事件。 所以你的udev规则应该只是阅读:

 ACTION=="add", SUBSYSTEMS=="input", ATTRS{idVendor}=="____", ATTRS{idProduct}=="____", RUN+="/usr/local/sbin/fixmouse" 

你应该用真实设备的idProductidProduct替换____。 要查找该信息:

 $ udevadm monitor 

连接你的BT鼠标。 阅读出现“KERNEL”的行, 类似于

  KERNEL[22576.118379] add /devices/pci0000:00/0000:00:1d.7/hci2/2-3/2-3.4/2-3.4:1.0/0003:192F:0916.0004/input/input23/mouse1 (input) 

要结束监控,只需输入CTRL + C,然后:

 $ udevadm info -a -p '/devices/pci0000:00/0000:00:1d.7/hci2/2-3/2-3.4/2-3.4' | grep -e "idVendor" -e "idProduct" 

您应该获得2或3对(idVendor,idProduct)值,具体取决于硬件的组合方式。 我的用例产量:

 ATTRS{idVendor}=="192f" ATTRS{idProduct}=="0916" ATTRS{idVendor}=="1a40" ATTRS{idProduct}=="0101" ATTRS{idVendor}=="1d6b" ATTRS{idProduct}=="0002" 

按照udev规则按照它们出现的顺序尝试它们。 通常最顶层的应该是好的。

完成后,执行:

 $ sudo mv /home/elios/Documents/FixMouse.sh /usr/local/sbin/fixmouse $ sudo chown root:root /usr/local/sbin/fixmouse $ sudo chmod 755 /usr/local/sbin/fixmouse 

希望我做对了。 无论哪种方式让我们知道。