[转]Ubuntu 下禁用触摸板的方法

from :http://blog.csdn.net/hunanchenxingyu/article/details/39214677

通过xinput可以来启用和禁用输入设备,以此来达到我需要的功能----禁用触摸板。

查看设备列表

通过xinput先查看一些都有哪些设备

xinput     #或者 xinput list

显示结果如下

ddd@ddd:~$ xinput list
 Virtual core pointer                        id=2    [master pointer  (3)]
   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
  ↳ PixArt USB Optical Mouse                    id=11    [slave  pointer  (2)]
   ↳ DualPoint Stick                             id=15    [slave  pointer  (2)]
   ↳ AlpsPS/2 ALPS DualPoint 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)]
    ↳ Video Bus                                   id=8    [slave  keyboard (3)]
    ↳ Power Button                                id=9    [slave  keyboard (3)]
    ↳ Sleep Button                                id=10    [slave  keyboard (3)]
    ↳ Integrated Webcam                           id=12    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard                id=13    [slave  keyboard (3)]
    ↳ Dell WMI hotkeys 

其中AlpsPS/2 ALPS DualPoint Touchpad就是我笔记本的触摸板,其中id=14为设备的编号。这两者是等价的。

看设备属性

xinput list-props 14
xinput list-props 'AlpsPS/2 ALPS DualPoint TouchPad'

显示部分结果如下:(不全,只是为了显示一下大概有什么内容)

ddd@ddd:~$ xinput list-props 'AlpsPS/2 ALPS DualPoint TouchPad'
Device 'AlpsPS/2 ALPS DualPoint TouchPad':
    Device Enabled (142):    1
    Coordinate Transformation Matrix (144):    1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    Device Accel Profile (264):    1
    Device Accel Constant Deceleration (265):    2.500000
    Device Accel Adaptive Deceleration (266):    1.000000

其中有个属性Device Enabled表示设备的是禁用还是启用,1表示启用,0表示禁用。另外括号中的142也是表示Device Enabled,这两者是等价的。上面提到的设备名称和设备id也是等价的。

用、启用触摸板

用过set-porp来设置设备的属性。

#禁用触摸板
xinput set-prop 14 'Device Enabled' 0  #通过设备编号+属性名禁用触摸板
xinput set-prop 'AlpsPS/2 ALPS DualPoint TouchPad' 'Device Enabled' 0 #通过设备名+属性名禁用触摸板
#启用触摸板
xinput set-prop 14 142 1 #通过设备编号+属性编号来设置
xinput set-prop 'AlpsPS/2 ALPS DualPoint TouchPad' 142 1 #通过设备名+属性编号启用

刚才说了在我的电脑AlpsPS/2 ALPS DualPoint Touchpad14是等价的,Device Enabled142是等价的,所以两者可以替代,于是敲命令的时候可以偷懒下。不过像这样看着比较直观这个命令到底是干什么。

xinput set-prop 'AlpsPS/2 ALPS DualPoint TouchPad' 'Device Enabled' 0

过脚本快速启用和禁用触摸板

每次如果都敲命令也是比较麻烦的,通过脚本就很快的切换了。

#!/bin/bash
if [ $1 = 'on' ]
then
    xinput set-prop 14 142 1
    echo "触摸板开启成功!"
elif [ $1 = 'off' ]
then
    xinput set-prop 'AlpsPS/2 ALPS DualPoint TouchPad' 'Device Enabled' 0
    echo "触摸板关闭成功!"
else
    echo "请输入参数:on/off"
    echo "开启触摸板:touchpadEnable on"
    echo "禁用触摸板:touchpadEnable off"
fi

通过禁用触摸板,确实给我解决了不少的麻烦。

开机自动禁用触摸板

但是这样在开机重启后又恢复了,对有些同学喜欢关机而不是休眠的同学确实还要改进,就是让开机的时候自动运行禁用触摸板的命令。
在~/.config/autostart/下创建一个启动器xinput.desktop文件,内容如下

[Desktop Entry]
Type=Application
Exec=xinput set-prop 'AlpsPS/2 ALPS DualPoint TouchPad' 'Device Enabled' 0
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[zh_CN]=touchpad enable
Name=touchpad enable
Comment[zh_CN]=禁用触摸板
Comment=禁用触摸板

这样在开机的时候就能自动禁用触摸板了。

不好的地方就是原来通过Fn+F8禁用触摸板时有灯亮的,现在不亮了,更好的方法应该是通过脚本模拟Fn+F8来禁用触摸板。

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

个性化:

首先在home目录下:$sudo gedit TouchPad.sh-->粘贴上面的shell代码-->执行: sh TouchPad.sh off(注意后面的参数)。


原文地址:https://www.cnblogs.com/ufindme/p/3991270.html