切换触摸屏:

切换触摸屏:

背景资料:
我的笔记本电脑上的触摸屏有问题,我曾经在启动时有一个特殊的 Bash 脚本来处理它,但我最近安装了 PureOS,以便更符合 GNU 的建议。我已经放弃在 Wayland 生态系统中寻找任何与 xinput 相近的东西,但是我不喜欢运行遗留软件,除非绝对被迫。篡改驱动程序之类的方法以及 libinput 提供的任何信息都是没有用的。唯一能够阻止我的触摸屏近乎伪随机行为的命令是神圣的evtest --grab。我想强调的是,如果不禁用触摸屏,我的工作笔记本电脑绝对毫无用处(除了 TTY)。


重要部分:
我一直在尝试创建一个脚本

  1. 检索输入设备列表:cat /proc/bus/input/devices
  2. 解析输出以找到段落"ELAN0732:00 04F3:264C"(我尝试过使用,awk但我不太了解)
  3. 区分上述和"ELAN0732:00 04F3:264C Pen"(这是两种不同的设备,笔不会引起任何问题,但我不需要它,所以如果它也因此被禁用,我不介意)
  4. 在该段落中,找到一个语句,其中eventNN 在每次重新启动时都是随机的(使用grep/ awk
  5. 跑步sudo evtest --grab /dev/input/event$N > /dev/null

此后,我会将这个脚本放在一个它将在启动时以root权限运行的地方(我已经看到了一些关于 的内容/etc/rc.local,但还没有尝试过)

evtest已经以单行打印输入设备,并且我将其变体放在一起:

sudo timeout 2 evtest --grab | grep "ELAN073 | grep "ELAN0732:00 04F3:264C"

但是grep无法正确解析(可能是由于 stdout 通过管道传输的方式),但即便如此,解析withtimeout可能会更好(按照上述步骤),而不是运行命令、管道输出、终止命令,解析它,再次运行它。/proc/bus/input/devicesawk


附加信息:
PureOS 9.0(基于 Debian 测试)、Linux 4.19.0-5-amd64
cat /proc/bus/input/devices打印:

N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input0
U: Uniq=
H: Handlers=sysrq kbd leds event0 
B: PROP=0
B: EV=120013
B: KEY=20000 20 0 0 1500f02100000 3803078f900d401 feffffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7

I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=PNP0C0C/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2
U: Uniq=
H: Handlers=kbd event1 
B: PROP=0
B: EV=3
B: KEY=10000000000000 0

I: Bus=0019 Vendor=0000 Product=0005 Version=0000
N: Name="Lid Switch"
P: Phys=PNP0C0D/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input3
U: Uniq=
H: Handlers=event2 
B: PROP=0
B: EV=21
B: SW=1

I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=LNXPWRBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input4
U: Uniq=
H: Handlers=kbd event3 
B: PROP=0
B: EV=3
B: KEY=10000000000000 0

I: Bus=0019 Vendor=0000 Product=0006 Version=0000
N: Name="Video Bus"
P: Phys=LNXVIDEO/video/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:14/LNXVIDEO:02/input/input6
U: Uniq=
H: Handlers=kbd event4 
B: PROP=0
B: EV=3
B: KEY=3e000b00000000 0 0 0

I: Bus=0011 Vendor=0002 Product=0007 Version=01a1
N: Name="SynPS/2 Synaptics TouchPad"
P: Phys=isa0060/serio1/input0
S: Sysfs=/devices/platform/i8042/serio1/input/input5
U: Uniq=
H: Handlers=mouse2 event9 
B: PROP=5
B: EV=b
B: KEY=e520 10000 0 0 0 0
B: ABS=660800011000003

I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="HP Wireless hotkeys"
P: Phys=hpq6001/input0
S: Sysfs=/devices/virtual/input/input13
U: Uniq=
H: Handlers=kbd event10 rfkill 
B: PROP=0
B: EV=3
B: KEY=80000000000000 0 0 0

I: Bus=0010 Vendor=001f Product=0001 Version=0100
N: Name="PC Speaker"
P: Phys=isa0061/input0
S: Sysfs=/devices/platform/pcspkr/input/input14
U: Uniq=
H: Handlers=kbd event11 
B: PROP=0
B: EV=40001
B: SND=6

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic HDMI/DP,pcm=3"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.1/sound/card0/input15
U: Uniq=
H: Handlers=event12 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0003 Vendor=04f2 Product=b634 Version=0012
N: Name="HP Wide Vision FHD Camera: HP W"
P: Phys=usb-0000:03:00.4-1/button
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.4/usb3/3-1/3-1:1.0/input/input16
U: Uniq=
H: Handlers=kbd event13 
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic Mic"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.6/sound/card1/input17
U: Uniq=
H: Handlers=event5 
B: PROP=0
B: EV=21
B: SW=10

I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="HP WMI hotkeys"
P: Phys=wmi/input0
S: Sysfs=/devices/virtual/input/input19
U: Uniq=
H: Handlers=kbd event6 
B: PROP=0
B: EV=33
B: KEY=4000000000 0 1000700000000 2102400 0 0
B: MSC=10
B: SW=0

I: Bus=0003 Vendor=04f2 Product=b634 Version=0012
N: Name="HP Wide Vision FHD Camera: HP I"
P: Phys=usb-0000:03:00.4-1/button
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.4/usb3/3-1/3-1:1.2/input/input20
U: Uniq=
H: Handlers=kbd event14 
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic Headphone"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.6/sound/card1/input18
U: Uniq=
H: Handlers=event7 
B: PROP=0
B: EV=21
B: SW=4

# THIS IS THE PARAGRAPH I NEED
I: Bus=0018 Vendor=04f3 Product=264c Version=0100
N: Name="ELAN0732:00 04F3:264C"
P: Phys=i2c-ELAN0732:00
S: Sysfs=/devices/platform/AMDI0010:00/i2c-0/i2c-ELAN0732:00/0018:04F3:264C.0001/input/input21
U: Uniq=
H: Handlers=mouse0 event8 #THIS IS THE EVENT NUMBER I NEED
B: PROP=2
B: EV=1b
B: KEY=400 0 0 0 0 0
B: ABS=3273800000000003
B: MSC=20

# THIS PARAGRAPH SHOULD BE IGNORED, OR BOTH CAN BE USED, BUT NOT EXCLUSIVELY THIS ONE
I: Bus=0018 Vendor=04f3 Product=264c Version=0100
N: Name="ELAN0732:00 04F3:264C Pen"
P: Phys=i2c-ELAN0732:00
S: Sysfs=/devices/platform/AMDI0010:00/i2c-0/i2c-ELAN0732:00/0018:04F3:264C.0001/input/input24
U: Uniq=
H: Handlers=mouse1 event15 
B: PROP=0
B: EV=1b
B: KEY=c03 0 0 0 0 0
B: ABS=1000003
B: MSC=10

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="BRLTTY 5.6 Linux Screen Driver Keyboard"
P: Phys=pid-692/brltty/14
S: Sysfs=/devices/virtual/input/input27
U: Uniq=
H: Handlers=sysrq kbd event16 
B: PROP=0
B: EV=100003
B: KEY=402000007 ffc03078f800d2a9 f2beffdfffefffff fffffffffffffffe

I: Bus=0005 Vendor=045e Product=082f Version=0206
N: Name="Microsoft Bluetooth Mouse Mouse"
P: Phys=80:2B:F9:52:CA:DC
S: Sysfs=/devices/virtual/misc/uhid/0005:045E:082F.0002/input/input28
U: Uniq=DD:47:30:64:95:63
H: Handlers=mouse3 event17 
B: PROP=0
B: EV=17
B: KEY=1f0000 0 0 0 0
B: REL=143
B: MSC=10

I: Bus=0005 Vendor=045e Product=082f Version=0206
N: Name="Microsoft Bluetooth Mouse Keyboard"
P: Phys=80:2B:F9:52:CA:DC
S: Sysfs=/devices/virtual/misc/uhid/0005:045E:082F.0002/input/input29
U: Uniq=DD:47:30:64:95:63
H: Handlers=sysrq kbd event18 
B: PROP=0
B: EV=100013
B: KEY=1000000000007 ff800000000007ff febeffdff3cfffff fffffffffffffffe
B: MSC=10

I: Bus=0005 Vendor=045e Product=082f Version=0206
N: Name="Microsoft Bluetooth Mouse"
P: Phys=80:2B:F9:52:CA:DC
S: Sysfs=/devices/virtual/misc/uhid/0005:045E:082F.0002/input/input30
U: Uniq=DD:47:30:64:95:63
H: Handlers=event19 
B: PROP=0
B: EV=9
B: ABS=10000000000

I: Bus=0005 Vendor=0000 Product=0000 Version=0000
N: Name="00:0A:45:0A:FB:49"
P: Phys=
S: Sysfs=/devices/virtual/input/input33
U: Uniq=
H: Handlers=kbd event20 
B: PROP=0
B: EV=100007
B: KEY=2fc800 145200000000 0 10300 49e800000c00 e16800000000f f810000010000ffc
B: REL=0

答案1

这应该是一个合适的 awk 脚本:

device=$( cat /proc/bus/input/devices |
  awk '
  /"ELAN0732:00 04F3:264C"/{ inside = 1 }
  /Handlers=/  { if(match($0,"event([0-9]+)",group))event = group[1] }
  /^$/         { if(inside && event!="")print "/dev/input/event" event
                 inside = 0; event = ""
  }')
if [ -n "$device" ]
then sudo evtest --grab "$device" > /dev/null &
fi

第一行匹配所需的字符串并设置变量inside以表明我们处于正确的节中。下一行查找Handlers并用于match(string, regexp, returnarray)查找正则表达式event[0-9]+并将数字捕获()到数组中group,然后设置变量event

最后,我们匹配每个节末尾的空行(包括最后一个),如果我们在内部并且有事件号,则打印与事件号连接的设备路径。

如果您的 awk 是 POSIX 而不是 GNU,请将 Handlers 行替换为

/Handlers=/{ if(split($0,part,"event"))event = part[2]+0 }

它在单词“event”处分割行,然后将以下字符转换为数字。

如果上面的脚本直接写入/etc/rc.local,请确保运行sudo chmod +x /etc/rc.local,否则不会执行。

该命令的末尾&是 Systemd 在启动时不挂起所必需的(因为它期望在继续之前退出,而我们需要它在整个正常运行时间内运行)。尝试/dev/null忽略evtest用于报告触摸屏使用情况的标准输出,以节省内存。添加/dev/null可能微不足道,但不会有坏处。

答案2

哦。非常感谢这个问题,它实际上给了我如何禁用触摸屏的答案。我的还可以,直到突然它变得非常弹道并且经常点击屏幕上的所有内容。

接受的解决方案很好很酷,但我只是想要一些我真正能理解的超级基本的东西。所以对于普通的 shell 来说可能是这样的:

sudo evtest --grab /dev/input/$(grep "SYNA2393" -A 5 /proc/bus/input/devices | grep "Handlers=" | cut -d" " -f 3)

这比公认的解决方案更脆弱,所以我建议读者使用它,除非他们喜欢这样的硬编码。

答案3

我正在全新安装 ubuntu 22.04。我不知道如何让 awk 的 match 函数工作,所以我只是使用 @meuh 和 @JinnKo 的代码来创建一个非 awk 版本,该版本可以在给定关键字的情况下禁用/切换多个设备。

首先,确保已安装 evtest:

sudo apt install evtest

我有两个文件,一个用于打开和关闭触摸屏,另一个在启动时始终将其禁用。

切换触摸屏:

#!/bin/bash
# This toggles my touchscreen
#search for "Touchscreen" or something like that in /proc/bus/input/devices to make sure you're disabling what you want to disable.

path_for_temp_files="/ANY_PATH_YOU_WANT_TO_STORE_SOME_PID_FILES/"
regex='event([0-9]+)'
DEVICE="Touchscreen"

if [ -r "${path_for_temp_files}touchscreen-evtest0.pid" ]; then
    kill_these_files=("${path_for_temp_files}"touchscreen-evtest*)

    for i in "${kill_these_files[@]}"; do
        echo "kill" $(cat "${i}")
        sudo kill $(cat "${i}")
        sudo rm "${i}"
    done  

else
    filename='/proc/bus/input/devices'
    inside=0
    events=()
    while read line; do
        if [[ $line =~ $DEVICE ]]; then 
            inside=1
        fi

        if [[ $line =~ $regex ]]; then
            if [[ "$inside" -eq 1 ]]; then
                events+=("${BASH_REMATCH[1]}")
            fi
            inside=0
        fi
    done < $filename
    
    numevents=${#events[@]}
    
    for (( i=0; i<${numevents}; i++ )); do
        sudo evtest --grab "/dev/input/event${events[$i]}" > /dev/null &
        pid=$!
        echo $pid > "${path_for_temp_files}touchscreen-evtest${i}.pid"
        echo "/dev/input/event${events[$i]} running on pid ${pid}"
    done
fi

禁用触摸屏在启动时运行:

#!/bin/bash
# This disables my touchscreen
#search for "Touchscreen" or something like that in /proc/bus/input/devices to make sure you're disabling what you want to disable.

path_for_temp_files="/ANY_PATH_YOU_WANT_TO_STORE_SOME_PID_FILES/"
regex='event([0-9]+)'
DEVICE="Touchscreen"

if [ -r "${path_for_temp_files}touchscreen-evtest0.pid" ]; then
    kill_these_files=("${path_for_temp_files}"touchscreen-evtest*)

    for i in "${kill_these_files[@]}"; do
        echo "kill" $(cat "${i}")
        sudo kill $(cat "${i}")
        sudo rm "${i}"
    done  

fi

filename='/proc/bus/input/devices'
inside=0
events=()
while read line; do
    if [[ $line =~ $DEVICE ]]; then 
        inside=1
    fi

    if [[ $line =~ $regex ]]; then
        if [[ "$inside" -eq 1 ]]; then
            events+=("${BASH_REMATCH[1]}")
        fi
        inside=0
    fi
done < $filename

numevents=${#events[@]}

for (( i=0; i<${numevents}; i++ )); do
    sudo evtest --grab "/dev/input/event${events[$i]}" > /dev/null &
    pid=$!
    echo $pid > "${path_for_temp_files}touchscreen-evtest${i}.pid"
    echo "/dev/input/event${events[$i]} running on pid ${pid}"
done

然后我就跟着这个答案在启动时以 root 身份运行

相关内容