最近发现在Ubuntu13.10中使用Fn+F9对触摸板的控制操作不灵了;
并且在黑夜、外置键盘时,按下这个组合键也很不方便,由此便想到使用命令行来切换触摸板状态;
脚本:~/bin/touchpadctrl
1 #!/bin/bash -
2 #===============================================================================
3 #
4 # FILE: touchpadctrl
5 #
6 # USAGE: ./touchpadctrl
7 #
8 # DESCRIPTION:
9 #
10 # OPTIONS: ---
11 # REQUIREMENTS: ---
12 # BUGS: ---
13 # NOTES: ---
14 # AUTHOR: linkscue (scue), linkscue@gmail.com
15 # ORGANIZATION:
16 # CREATED: 2014年03月09日 12时57分34秒 CST
17 # REVISION: ---
18 #===============================================================================
19
20 # xinput --list ==> 获取TouchPad的id号(我的是13)
21 # xinput --list-props 13 ==> 获取TouchPad的设备状态
22 # man xinput ==> 获取xinput的使用方法
23 on(){
24 #synclient TouchpadOff=0
25 xinput set-prop 13 'Device Enabled' 1
26 echo -e "\e[0;36mtouchpad on.\e[0m" # cyan
27 exit
28 }
29 off(){
30 #synclient TouchpadOff=1
31 xinput set-prop 13 'Device Enabled' 0
32 echo -e "\e[0;36mtouchpad off.\e[0m" # cyan
33 exit
34 }
35
36 usage(){
37 echo -e "\e[0;31m==> Usage: $(basename $0) [ON/off/toggle].\e[0m" # red
38 exit
39 }
40
41 getstate(){
42 echo $(xinput --list-props 13 | grep Enable | awk -F: '{print $2}')
43 }
44
45 toggle(){
46 echo -en "\e[0;31m==> toggle: \e[0m" # red
47 case $(getstate) in
48 "0" ) on
49 ;;
50 "1" ) off
51 ;;
52 esac
53 }
54
55 # detect: help
56 if [[ ${1} != "" ]]; then
57 case ${1} in
58 "-h" | "--help" | "-help" )
59 usage
60 ;;
61 esac
62 fi
63
64 if [[ $# == 0 ]]; then
65 # auto swtich
66 if [[ $(lsusb | grep 'Sunplus Innovation Technology') != "" ]]; then
67 off
68 else
69 toggle
70 fi
71 else
72 # manual
73 case ${1} in
74 "of"|"off"|"OFF"|"Off") off
75 ;;
76 "t"|"toggle"|"T"|"Toggle") toggle
77 ;;
78 *) on
79 ;;
80 esac
81 fi
使用举例:
1. touchpadctrl
-- 有外置鼠标时,自动off,否则toggle
2. touchpadctrl on
-- 启用触摸板
3. touchpadctrl off
-- 禁用触摸板
4. touchpadctrl toggle
-- 切换触摸板状态