gpt4 book ai didi

shell - 如何制作一个程序来查找 xinput 设备的 id 并设置 xinput 一些设置

转载 作者:行者123 更新时间:2023-12-03 13:22:09 26 4
gpt4 key购买 nike

我有一个 G700 鼠标连接到我的电脑。这个鼠标在 Linux (Ubuntu) 中的问题是灵敏度非常高。我也不喜欢鼠标加速,所以我制作了一个脚本来关闭它。脚本看起来像这样

#!/bin/bash
# This script removes mouse acceleration, and lowers pointer speed
# Suitable for gaming mice, I use the Logitech G700.
# More info: http://www.x.org/wiki/Development/Documentation/PointerAcceleration/
xinput set-prop 11 'Device Accel Profile' -1
xinput set-prop 11 'Device Accel Constant Deceleration' 2.5
xinput set-prop 11 'Device Accel Velocity Scaling' 1.0
xinput set-prop 12 'Device Accel Profile' -1
xinput set-prop 12 'Device Accel Constant Deceleration' 2.5
xinput set-prop 12 'Device Accel Velocity Scaling' 1.0

G700 鼠标的另一个问题是它在 xinput 中显示为两个不同的设备。这很可能是因为鼠标具有无线适配器,并且通常也通过 USB 电缆连接(用于充电)。这是我来自 xinput --list 的输出(参见 ID 11 和 12):
$ xinput --list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=8 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=9 [slave pointer (2)]
⎜ ↳ Logitech Unifying Device. Wireless PID:4003 id=10 [slave pointer (2)]
⎜ ↳ Logitech G700 Laser Mouse id=11 [slave pointer (2)]
⎜ ↳ Logitech G700 Laser Mouse id=12 [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)]
↳ Power Button id=7 [slave keyboard (3)]

这通常不是问题,因为 id 通常是相同的。但有时鼠标的 id 会发生变化,这就是我的问题所在。

编写找到属于两个名为 Logitech G700 Laser Mouse 的列表的 ID 的脚本/程序的最简单方法是什么?在 xinput --list 的输出中,然后使用这两个 ID 运行顶部脚本中的命令?

最佳答案

您可以执行以下操作。

if [ "$SEARCH" = "" ]; then 
exit 1
fi

ids=$(xinput --list | awk -v search="$SEARCH" \
'$0 ~ search {match($0, /id=[0-9]+/);\
if (RSTART) \
print substr($0, RSTART+3, RLENGTH-3)\
}'\
)

for i in $ids
do
xinput set-prop $i 'Device Accel Profile' -1
xinput set-prop $i 'Device Accel Constant Deceleration' 2.5
xinput set-prop $i 'Device Accel Velocity Scaling' 1.0
done

因此,您首先要找到与搜索模式匹配的所有 ID $SEARCH并将它们存储在 $ids .
然后循环遍历 ID 并执行三个 xinput命令。

您应该确保 $SEARCH不匹配太多,因为这可能导致不良行为。

关于shell - 如何制作一个程序来查找 xinput 设备的 id 并设置 xinput 一些设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18755967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com