我编写了一个小程序来切换设备是否启用,主要是通过热键运行以启用/禁用触摸板,因为我的手在打字时总是碰到它。我用它notify-send来创建一个对话框,但是我目前所能做的就是说
device $1 has been enabled
Run Code Online (Sandbox Code Playgroud)
xinput 列表的输出如下所示:
? Virtual core pointer id=2 [master pointer (3)]
? ? Virtual core XTEST pointer id=4 [slave pointer (2)]
? ? Atmel Atmel maXTouch Digitizer id=10 [slave pointer (2)]
? ? ETPS/2 Elantech Touchpad id=14 [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)]
? USB2.0 HD UVC WebCam id=11 [slave keyboard (3)]
? Asus WMI hotkeys id=12 [slave keyboard (3)]
? AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
Run Code Online (Sandbox Code Playgroud)
Is there any easy way to reliably get ETPS/2 Elantech Touchpad or USB2.0 HD UVC WebCam? A regex won't correctly match unless I look for the ? character, something in between, then multiple spaces, but is that a valid character for a regex?
Edit : The script is simple so I've included it, it's called with a device number (would be cool if I could also toggle_device touchpad but that's a later problem)
#!/bin/bash
DEVICE_ENABLED=`xinput list-props $1 | grep "Enabled" | awk '{print $NF}'`
if [ "$DEVICE_ENABLED" == "1" ] #disable if it's enabled
then
xinput set-prop $1 "Device Enabled" 0
notify-send "Device $1 has been disabled"
else
xinput set-prop $1 "Device Enabled" 1
notify-send "Device $1 has been enabled"
fi
Run Code Online (Sandbox Code Playgroud)
In practice, yes, you can do that.
arrow=$'\xe2\x86\xb3'
while IFS= read -r line; do
if [[ $line = *"$arrow"* ]]; then
content=${line#*"$arrow"} # delete everything before the arrow
content=${line%%$'\t'*} # delete everything after first tab
echo "Found content: $content"
fi
done < <(xinput --list)
Run Code Online (Sandbox Code Playgroud)
That said, it's easier to call xinput --list --name-only, and not need to filter.