如何使用命令行禁用触摸板?
有没有办法使用终端命令禁用触摸板?
要关闭触摸板:
synclient TouchpadOff=1
要重新打开它:
synclient TouchpadOff=0
你可以尝试至少两种方法(我知道)。
synclient
如果您的笔记本电脑配备了Synaptics(或ALPS)触摸板,您确实可以使用synclient
已经提到的synclient。 我正在运行Ubuntu 14.04并且在我的机器上默认安装它。
测试是否安装了synclient -V
: synclient -V
(它应报告版本号)
打开触摸板: synclient TouchpadOff=0
关闭触摸板: synclient TouchpadOff=1
我自己没有测试过,但如果你的目标是当你的arm放在触摸板上时不移动鼠标,这可能会有所帮助。
打开手掌检测: synclient PalmDetect=1
关闭手掌检测: synclient PalmDetect=0
通常,您可以通过synclient property=value
配置Synaptics触摸板的任何属性。 其中属性是synclient -l
显示的可用属性之一
进一步阅读的链接
ubuntu – comminity help wiki – SynapticsTouchpad
archlinux – wiki – 触控板Synaptics
问ubuntu – 如何让我的synclient设置坚持下去? – Ubuntu
XINPUT
如果您不想或不能使用synclient,您也可以使用xinput
。 程序有点类似。
列出所有xinput设备: xinput
部分输出可能如下所示:
⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech USB-PS/2 Optical Mouse id=13 [slave pointer (2)] ⎜ ↳ ETPS/2 Elantech Touchpad id=17 [slave pointer (2)]
这个特殊情况我的触摸板有id = 17,它的全名是“ETPS / 2 Elantech Touchpad”。
设置属性的命令是xinput set-prop
。 启用或禁用触摸板的属性是“已启用Device Enabled
,因此要启用或禁用它,请键入:
打开触摸板: xinput set-prop
(其中
是您的设备ID,在我的情况下为17)
关闭触摸板: xinput set-prop
打开手掌检测: xinput set-prop
关闭手掌检测: xinput set-prop
要查询可用属性: xinput list-props
或xinput list-props
,这应该与synclient -l
非常类似。
进一步阅读的链接
ubuntu – 维基 – 输入
注意
通过xinput
或synclient
设置属性时,属性不会设置为其他工具。 它们也没有设置在统一控制中心。
如果您使用gnome(或unity,cinnamon)环境, synclient
和xinput
将无法工作,因为它将覆盖设置,因此如果您希望synclient
或xinput
接管这些设置,您应首先禁用它:
-
如果没有安装,请安装
dconf-editor
:apt-get install dconf-editor
-
运行
dconf-editor
dconf-editor
-
打开目录
/org/gnome/settings-daemon/plugins/mouse/
或/org/cinnamon/settings-daemon/plugins/mouse/
,然后取消选中active
的复选框。 -
logout
或reboot
这应该使synclient
或xinput
工作。
-
列出您的输入设备:
xinput list
就我而言,我有这个清单:
Virtual core XTEST pointer id=4 Logitech M510 id=11 ETPS/2 Elantech Touchpad id=15
-
通过传递ID来禁用触摸板
xinput set-prop 15 "Device Enabled" 0
我编写了一段python代码,以便您可以使用xinput
技术而无需完成所有手动工作。 Copyleft,AS-IS,无保修,使用风险由您自行承担。 对我来说很有用:如果你使用gnome,只需将它映射到Ctrl Shift T等关键快捷键 。
#!/usr/bin/python2 # -*- coding: utf-8 -*- '''Program to toggle Touchpad Enable to Disable or vice-versa.''' import commands import re def current_id(): """ Search through the output of xinput and find the line that has the word TouchPad. At that point, I believe we can find the ID of that device.""" props = commands.getoutput("xinput").split("\n") match = [line for line in props if "TouchPad" in line] assert len(match) == 1, "Problem finding Touchpad string! %s" % match pat = re.match(r"(.*)id=(\d+)", match[0]) assert pat, "No matching ID found!" return int(pat.group(2)) def current_status(tpad_id): """Find the current Device ID, it has to have the word TouchPad in the line.""" props = commands.getoutput("""xinput list-props %d""" % tpad_id).split('\n') match = [line for line in props if "Device Enabled" in line] assert len(match) == 1, "Can't find the status of device #%d" % tpad_id pat = re.match(r"(.*):\s*(\d+)", match[0]) assert pat, "No matching status found!" return int(pat.group(2)) def flop(tpad_id, status): """Change the value of status, and call xinput to reverse that status.""" if status == 0: status = 1 else: status = 0 print "Changing Device #%d Device Enabled %d" % (tpad_id, status) commands.getoutput("""xinput set-prop %d "Device Enabled" %d""" % (tpad_id, status)) def main(): """Get curent device id and status, and flop status value.""" tpad = current_id() stat = current_status(tpad) flop(tpad, stat) main()