春暖花开

在 Linux 中如何通过命令行开启或禁用触摸板

本文将介绍如何在 Linux 中如何使用命令行命令来打开和关闭触摸板。

xinput

首先,需要了解一个工具:xinput

1
2
xinput is a utility to list available input devices, query information
about a device and change input device settings.

上面是 man 手册对它的描述。

要通过触摸板开启或关闭触摸板,首先要要获取触摸板的设备 ID 和属性。

我们可以可以先通过 xinput --list 命令查看有哪些输入设备。下面的结果是在我的笔记本上的输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PixArt USB Optical Mouse id=10 [slave pointer (2)]
⎜ ↳ DELL0767:00 06CB:7E92 Touchpad id=12 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics 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)]
↳ Integrated Webcam id=11 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
↳ Dell WMI hotkeys id=15 [slave keyboard (3)]
↳ DELL Wireless hotkeys id=16 [slave keyboard (3)]

可以看到,第 4 行输出即为触摸板,后面的 id 即为设备号。

下面,查看触摸板的属性:

1
2
3
xinput --list-props 12
#或
xinput --list-props ‘DELL0767:00 06CB:7E92 Touchpad’

即使用设备 id 或设备名作为后面的参数均可以。

下面是在我的笔记本上的输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Device 'DELL0767:00 06CB:7E92 Touchpad':
Device Enabled (140): 0
Coordinate Transformation Matrix (142): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (263): 1
Device Accel Constant Deceleration (264): 2.500000
Device Accel Adaptive Deceleration (265): 1.000000
Device Accel Velocity Scaling (266): 12.500000
Synaptics Edges (288): 49, 1180, 50, 879
Synaptics Finger (289): 25, 30, 0
Synaptics Tap Time (290): 180
Synaptics Tap Move (291): 67
Synaptics Tap Durations (292): 180, 180, 100
Synaptics ClickPad (293): 1
Synaptics Middle Button Timeout (294): 0
Synaptics Two-Finger Pressure (295): 282
Synaptics Two-Finger Width (296): 7
Synaptics Scrolling Distance (297): 30, 30
Synaptics Edge Scrolling (298): 0, 0, 0
Synaptics Two-Finger Scrolling (299): 1, 1
Synaptics Move Speed (300): 1.000000, 1.750000, 0.129870, 0.000000
Synaptics Off (301): 0
Synaptics Locked Drags (302): 0
Synaptics Locked Drags Timeout (303): 5000
Synaptics Tap Action (304): 2, 3, 0, 0, 1, 3, 2
Synaptics Click Action (305): 1, 3, 0
Synaptics Circular Scrolling (306): 0
Synaptics Circular Scrolling Distance (307): 0.100000
Synaptics Circular Scrolling Trigger (308): 0
Synaptics Circular Pad (309): 0
Synaptics Palm Detection (310): 0
Synaptics Palm Dimensions (311): 10, 200
Synaptics Coasting Speed (312): 20.000000, 50.000000
Synaptics Pressure Motion (313): 30, 160
Synaptics Pressure Motion Factor (314): 1.000000, 1.000000
Synaptics Resolution Detect (315): 1
Synaptics Grab Event Device (316): 0
Synaptics Gestures (317): 1
Synaptics Capabilities (318): 1, 0, 0, 1, 1, 0, 0
Synaptics Pad Resolution (319): 12, 12
Synaptics Area (320): 0, 0, 0, 0
Synaptics Soft Button Areas (321): 614, 0, 761, 0, 0, 0, 0, 0
Synaptics Noise Cancellation (322): 7, 7
Device Product ID (258): 1739, 32402
Device Node (259): "/dev/input/event15"

可以看到,第一个属性即为触摸板状态:1 表示开启,0 表示关闭,属性编号为 140。

之后,我们可以使用下面的命令来开启或关闭触摸板:

1
2
3
4
# 开启触摸板
xinput set-prop 12 140 1
# 关闭触摸板
xinput set-prop 12 140 0

其中,设备 ID 和属性编号也可替换为名字。

但是,每次都使用这个命令会比较麻烦,因此,可以通过一个简单的脚本来实现:

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
if [ "$1" == "on" ]; then
xinput set-prop 12 140 1;
echo "Touchpad successfully enabled!";
elif [ "$1" == "off" ]; then
xinput set-prop 12 140 0;
echo "Touchpad successfully disabled!"
else
echo "Please use the program with one of the following arguments:"
echo " (1) on : enable the touchpad!"
echo " (2) off : disable the touchpad!"
fi

将该脚本命名为 touchpad ,然后放到 /home/user/bin 目录下。然后,开启或关闭触摸板就很方便了:

1
2
3
4
# 开启触摸板
touchpad on
# 关闭触摸板
touchpad off

注意,脚本中的设备 ID 和属性编号应和你的笔记本一致,user 为你的用户名。

gsettings

另外,如果上面的命令不起用了,那么可以试试(Gnome):

1
2
3
4
5
6
7
8
开启触摸板:
sudo gsettings set org.gnome.desktop.peripherals.touchpad send-events true
输入时禁用:
sudo gsettings set org.gnome.desktop.peripherals.touchpad disable-while-typing true
双指滚动
sudo gsettings set org.gnome.desktop.peripherals.touchpad disable-while-typing true
tap to click:
sudo gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true
0%